Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

In this page you can find the example usage for javax.swing JTextField setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:edu.harvard.mcz.imagecapture.ui.FilteringAgentJComboBox.java

protected void filter(String enteredText, boolean changePopupState) {
    log.debug(enteredText);//from  w w w. j  a va  2s.c om
    log.debug("changePopupState:" + changePopupState);
    if (enteredText == null || enteredText.length() == 0 || enteredText.length() < lastTextLength) {
        // If entry is blank, show full list.
        if (cachedModel == null || (enteredText != null && enteredText.length() < lastTextLength)) {
            log.debug("Querying for new list");
            MCZbaseAuthAgentNameLifeCycle uls = new MCZbaseAuthAgentNameLifeCycle();
            cachedModel = new AgentNameComboBoxModel(uls.findAll());
        } else {
            log.debug("Reusing old agent list lenght = " + cachedModel.getSize());
        }
        super.setModel(cachedModel);
    }
    if (!changePopupState) {
        this.firePopupMenuCanceled();
    }
    if (changePopupState && !this.isPopupVisible()) {
        this.showPopup();
    }

    int lengthThreshold = Integer.valueOf(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_FILTER_LENGTH_THRESHOLD));
    if (enteredText != null && enteredText.length() >= lengthThreshold) {

        log.debug("Filtering on " + enteredText);

        boolean isExactMatch = false;
        AgentNameComboBoxModel filterArray = new AgentNameComboBoxModel();
        filterArray.removeAllElements();
        log.debug("Model size: " + super.getModel().getSize());
        for (int i = 0; i < super.getModel().getSize(); i++) {
            if (((AgentNameComboBoxModel) super.getModel()).getDataElementAt(i).toString().toLowerCase()
                    .contains(enteredText.toLowerCase())) {
                filterArray.addElement(
                        (MCZbaseAuthAgentName) ((AgentNameComboBoxModel) super.getModel()).getDataElementAt(i));
            }
            if (((AgentNameComboBoxModel) super.getModel()).getDataElementAt(i).toString()
                    .equalsIgnoreCase(enteredText)) {
                isExactMatch = true;
                super.getModel()
                        .setSelectedItem(((AgentNameComboBoxModel) super.getModel()).getDataElementAt(i));
            }
        }
        if (filterArray.getSize() > 0) {
            AgentNameComboBoxModel model = (AgentNameComboBoxModel) this.getModel();
            model.removeAllElements();
            Iterator<MCZbaseAuthAgentName> i = filterArray.getModel().iterator();
            while (i.hasNext()) {
                model.addElement(i.next());
            }
            JTextField textfield = (JTextField) this.getEditor().getEditorComponent();
            textfield.setText(enteredText);
            super.setModel(model);
        }
        log.debug("Filtered Model size: " + super.getModel().getSize());
        if (changePopupState) {
            this.hidePopup();
            if (isExactMatch) {
                super.firePopupMenuCanceled();
            } else {
                this.showPopup();
            }
        }
    }
    if (enteredText != null) {
        lastTextLength = enteredText.length();
    } else {
        lastTextLength = 0;
    }
}

From source file:com.mgmtp.perfload.loadprofiles.ui.component.DoubleCellEditor.java

public DoubleCellEditor() {
    super(new JTextField());
    final JTextField textField = (JTextField) getComponent();
    textField.setHorizontalAlignment(SwingConstants.RIGHT);
    delegate = new EditorDelegate() {
        @Override/* w  w  w  .  j a va2s . c  o m*/
        public void setValue(final Object value) {
            textField.setText(value != null ? FORMAT.format(value) : null);
        }

        @Override
        public Object getCellEditorValue() {
            return textField.getText();
        }
    };
    textField.addActionListener(delegate);
}

From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java

private void executeNumber(char word, JTextField value) {
    if (!StringUtils.isNumeric(value.getText())) {
        value.setText("0");
        GUIHelpers.displayErrorDialog("Provide numeric input.");
        return;/*from w  ww .ja  va2 s.  c  o  m*/
    }
    if (backend.isIdle()) {
        try {
            backend.sendGcodeCommand(word + value.getText());
        } catch (Exception ex) {
            GUIHelpers.displayErrorDialog(ex.getLocalizedMessage());
        }
    }
}

From source file:ViewDB.java

 /**
 * Shows a database row by populating all text fields with the column values.
 *///  w w w  .  ja  v a  2 s . co  m
public void showRow(ResultSet rs) throws SQLException
{
   for (int i = 1; i <= fields.size(); i++)
   {
      String field = rs.getString(i);
      JTextField tb = (JTextField) fields.get(i - 1);
      tb.setText(field);
   }
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    pnl.add(new JLabel("Enter text"));
    final JTextField txtText;
    txtText = new JTextField("to be removed");
    pnl.add(txtText);//w  w w .  j  a va 2 s .co  m

    JButton btnRemove = new JButton("Remove");
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String text = txtText.getText();
            text = Normalizer.normalize(text, Normalizer.Form.NFD);
            txtText.setText(text.replaceAll("[^\\p{ASCII}]", ""));
        }
    };
    btnRemove.addActionListener(al);
    pnl.add(btnRemove);
    add(pnl);
    pack();
    setVisible(true);
}

From source file:edu.harvard.mcz.imagecapture.ui.FilteringGeogJComboBox.java

protected void filter(String enteredText, boolean changePopupState) {
    if (countryLimit != null && countryLimit.length() == 0) {
        countryLimit = null;//from w  w  w.  j  a  v a 2  s . c o  m
    }
    if (stateprovLimit != null && stateprovLimit.length() == 0) {
        stateprovLimit = null;
    }
    if (enteredText == null || enteredText.length() == 0 || lastTextLength < enteredText.length()) {
        // If entry is blank, show full list.
        MCZbaseGeogAuthRecLifeCycle uls = new MCZbaseGeogAuthRecLifeCycle();
        if (countryLimit == null && stateprovLimit == null) {
            if (cachedModel == null || (enteredText == null || enteredText.length() < lastTextLength)) {
                cachedModel = new HigherGeographyComboBoxModel(uls.findAll());
            }
            super.setModel(cachedModel);
        } else {
            MCZbaseGeogAuthRec pattern = new MCZbaseGeogAuthRec();
            if (countryLimit != null && countryLimit.length() > 0) {
                pattern.setCountry(countryLimit);
            } else {
                if (stateprovLimit != null && stateprovLimit.length() > 0) {
                    pattern.setState_prov(stateprovLimit);
                }
            }
            if (cachedModel == null || (enteredText == null || enteredText.length() < lastTextLength)) {
                cachedModel = new HigherGeographyComboBoxModel(uls.findByExample(pattern));
            }
            super.setModel(cachedModel);
        }
    }
    if (!changePopupState) {
        this.firePopupMenuCanceled();
    }
    if (changePopupState && !this.isPopupVisible()) {
        this.showPopup();
    }

    int lengthThreshold = Integer.valueOf(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_FILTER_LENGTH_THRESHOLD));
    if (enteredText != null && enteredText.length() >= lengthThreshold) {

        log.debug("Filtering on " + enteredText);

        boolean isExactMatch = false;
        HigherGeographyComboBoxModel filterArray = new HigherGeographyComboBoxModel();
        filterArray.removeAllElements();
        log.debug("Model size: " + super.getModel().getSize());
        for (int i = 0; i < super.getModel().getSize(); i++) {
            if (((HigherGeographyComboBoxModel) super.getModel()).getDataElementAt(i).toString().toLowerCase()
                    .contains(enteredText.toLowerCase())) {
                filterArray.addElement((MCZbaseGeogAuthRec) ((HigherGeographyComboBoxModel) super.getModel())
                        .getDataElementAt(i));
            }
            if (((HigherGeographyComboBoxModel) super.getModel()).getDataElementAt(i).toString()
                    .equalsIgnoreCase(enteredText)) {
                isExactMatch = true;
                super.getModel()
                        .setSelectedItem(((HigherGeographyComboBoxModel) super.getModel()).getDataElementAt(i));
            }
        }
        if (filterArray.getSize() > 0) {
            HigherGeographyComboBoxModel model = (HigherGeographyComboBoxModel) this.getModel();
            model.removeAllElements();
            Iterator<MCZbaseGeogAuthRec> i = filterArray.getModel().iterator();
            while (i.hasNext()) {
                model.addElement(i.next());
            }
            JTextField textfield = (JTextField) this.getEditor().getEditorComponent();
            textfield.setText(enteredText);
            super.setModel(model);
        }
        log.debug("Filtered Model size: " + super.getModel().getSize());
        if (changePopupState) {
            this.hidePopup();
            if (isExactMatch) {
                super.firePopupMenuCanceled();
            } else {
                this.showPopup();
            }
        }
    }
    if (enteredText == null) {
        lastTextLength = 0;
    } else {
        lastTextLength = enteredText.length();
    }
}

From source file:RemoveAccents.java

public RemoveAccents() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    pnl.add(new JLabel("Enter text"));
    final JTextField txtText;
    txtText = new JTextField("to be removed");
    pnl.add(txtText);/*from   w ww  . j a  v a2 s . c  o m*/

    JButton btnRemove = new JButton("Remove");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String text = txtText.getText();
            text = Normalizer.normalize(text, Normalizer.Form.NFD);
            txtText.setText(text.replaceAll("[^\\p{ASCII}]", ""));
        }
    };
    btnRemove.addActionListener(al);
    pnl.add(btnRemove);

    getContentPane().add(pnl);

    pack();
    setVisible(true);
}

From source file:cz.alej.michalik.totp.client.AddDialog.java

/**
 * Naformtuje sdlen heslo//from   ww  w  .  j  av a 2 s.  co m
 * 
 * @param secret
 *            textov pole se sdlenm heslem
 * @return
 */
private void sanitize(final JTextField secret) {
    // Velk psmena a odstrann mezer
    String text = secret.getText().toUpperCase().trim().replaceAll(" ", "");
    secret.setText(text);
}

From source file:cool.pandora.modeller.ui.jpanel.iiif.CreateListsFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();/*from  ww w. j ava  2s .co  m*/
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("CreateListsFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Create List in:")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = IIIFObjectURI.getListContainerURI(map);
    try {
        urlField.setText(uri != null ? uri.toString() : null);
    } catch (final Exception e) {
        log.error("Failed to set url label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:cool.pandora.modeller.ui.jpanel.iiif.PatchCanvasFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();// w ww. ja  va 2s .  c o  m
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("PatchCanvasFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Patch Canvases")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = IIIFObjectURI.getCanvasContainerURI(map);
    try {
        urlField.setText(uri != null ? uri.toString() : null);
    } catch (final Exception e) {
        log.error("Failed to set url label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}