Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:com.diversityarrays.dal.server.AskServerParams.java

private void ensureFileChooser(JTextField path, File initCurrentDir) {
    String tmp = path.getText().trim();
    if (fileChooser == null) {
        if (tmp != null) {
            fileChooser = new JFileChooser(new File(tmp));
        } else {/*from   w w w . j a  v  a 2  s  .c  om*/
            fileChooser = new JFileChooser(initCurrentDir);
        }
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    } else {
        if (tmp != null) {
            fileChooser.setCurrentDirectory(new File(tmp));
        }
    }
}

From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java

public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel,
        boolean showCancel) {
    super(dialogTitle);

    JPanel framePanel = new JPanel();
    framePanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    framePanel.setLayout(new BorderLayout());

    // NORTH panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH);

    final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH);

    // data//from  ww w. j av a 2  s.  c o m
    tags = MindRaider.tagCustodian.getAllTags();
    ;
    if (tags == null) {
        tagLabel.setEnabled(false);
    }
    tagLabel.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                logger.debug("Openning selected tag...");
                openTagSearchDialog();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
            getListModel().clear();
            shownTags.clear();
            if (tagLabel.getText().length() > 0) {
                for (TagEntry tag : tags) {
                    if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) {
                        getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                        shownTags.add(tag);
                    }
                }
            } else {
                // show all tags
                for (TagEntry tag : tags) {
                    getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                    shownTags.add(tag);
                }
            }
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    northPanel.add(tagLabel, BorderLayout.SOUTH);
    framePanel.add(northPanel, BorderLayout.NORTH);

    // CENTER panel
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH);

    defaultListModel = new DefaultListModel();
    list = new JList(defaultListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    // list.addListSelectionListener(this);
    list.setVisibleRowCount(15);
    JScrollPane listScrollPane = new JScrollPane(list);
    centerPanel.add(listScrollPane, BorderLayout.SOUTH);
    framePanel.add(centerPanel, BorderLayout.CENTER);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton openButton = new JButton(buttonLabel);
    southPanel.add(openButton);
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openTagSearchDialog();
        }
    });

    if (showCancel) {
        JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel"));
        southPanel.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                OpenConceptByTagJDialog.this.dispose();
            }
        });
    }

    framePanel.add(southPanel, BorderLayout.SOUTH);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java

private boolean isMissingTextField(JTextField textBox, StringBuilder missingFieldMessage) {
    if (textBox.getText().equals("")) {
        if (missingFieldMessage.length() > 0)
            missingFieldMessage.append(", " + textBox.getName());
        else/*from ww  w .ja  v  a  2 s  .  c  o m*/
            missingFieldMessage.append(textBox.getName());
        return true;
    }
    return false;
}

From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java

/**
 * Determine bean property for a component and sets it up with appropriate listeners.
 * //from ww w. j  av  a2s  .  c  o  m
 * @param component the component
 * 
 * @return the bean property
 */
private BeanProperty setupComponent(final JComponent component) {
    if (component instanceof JTextField) {
        final JTextField tf = (JTextField) component;
        tf.getDocument().addDocumentListener(new DefaultDocumentListener() {
            @Override
            protected void changed() {
                if (component.getParent() instanceof JComboBox) {
                    JComboBox comboBox = (JComboBox) component.getParent();
                    labelHandler.handleLabelStateFor(comboBox,
                            Util.DEFAULT_NO_SELECTION_ENTRY.equals(tf.getText()));
                } else {
                    labelHandler.handleLabelStateFor(component, StringUtils.isEmpty(tf.getText()));
                }
                labelHandler.handleLabelStateFor(component, tf.getText().isEmpty());
            }
        });
        return BP_TEXT;
    } else if (component instanceof JComboBox) {
        final JComboBox box = (JComboBox) component;
        addListenerForEditableCombobox(box, new EditableComboboxListener() {
            @Override
            public void itemChanged(Object item) {
                labelHandler.handleLabelStateFor(component, Util.DEFAULT_NO_SELECTION_ENTRY.equals(item));
            }
        });
        return BP_COMBO;
    } else if (component instanceof MultivaluePanel) {
        return BP_MVALUE;
    } else if (component instanceof JXDatePicker) {
        final JXDatePicker picker = (JXDatePicker) component;
        picker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (picker.getDate() != null) {
                    labelHandler.handleLabelStateFor(component, false);
                } else {
                    labelHandler.handleLabelStateFor(component, true);
                }
            }
        });
        return BP_DATEPICKER;
    } else if (component instanceof DateTimePicker) {
        final DateTimePicker picker = (DateTimePicker) component;
        picker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (picker.getDateTime() != null) {
                    labelHandler.handleLabelStateFor(component, false);
                } else {
                    labelHandler.handleLabelStateFor(component, true);
                }
            }
        });
        return BP_DATETIMEPICKER;
    } else if (component instanceof JCheckBox) {
        return BP_CHECKBOX;
    } else if (component instanceof CertificateProperty) {
        return BP_CERTIFICATE_PROPERTY;
    }

    return null;
}

From source file:edu.ku.brc.specify.config.init.DatabasePanel.java

/**
 * Checks all the textfields to see if they have text
 * @return true of all fields have text//from  w ww . ja  v a 2  s. c om
 */
@Override
public boolean isUIValid() {
    label.setText("");

    JTextField[] txtFields = { usernameTxt, passwordTxt, dbNameTxt };
    for (JTextField tf : txtFields) {
        if (StringUtils.isEmpty(tf.getText())) {
            return isOKForCreateBtn = false;
        }
    }

    isOKForCreateBtn = true;

    if (!checkForValidText(label, dbNameTxt.getText(), "ERR_BAD_DBNAME", "NO_SPC_DBNAME", false)
            || !checkForValidText(label, usernameTxt.getText(), "ERR_BAD_USRNAME", "NO_SPC_USRNAME", false)
            || !checkForValidText(label, passwordTxt.getText(), null, "NO_SPC_PWDNAME", true)) {
        isOK = false;
        isOKForCreateBtn = false;
    }

    if (isOKForCreateBtn && UIRegistry.isEmbedded() && usernameTxt.getText().toLowerCase().equals("root")) {
        isOK = false;
        isOKForCreateBtn = false;

        label.setForeground(Color.RED);
        label.setText(getResourceString("ERR_NO_ROOT_EMBEDDED"));
        label.setVisible(true);
    }

    return (isOK != null && isOK) || manualLoginOK;
}

From source file:vinci.project2.pkg1.View.java

private void percentTest(JTextField fieldName, JLabel labelName) {
    String testS = fieldName.getText();

    if (testS.equals("")) {
        labelName.setForeground(red);/*from   w  ww .ja v  a 2  s  .c  o  m*/
        calcButton.setEnabled(false);
    } else {
        try {
            double testD = Double.parseDouble(fieldName.getText());
            if ((testD >= 0) && (testD <= 1)) {
                Double.parseDouble(iTaxField.getText());
                labelName.setForeground(black);
                calcButton.setEnabled(true);
            } else
                labelName.setForeground(red);
            calcButton.setEnabled(false);
        } catch (NumberFormatException e) {
            labelName.setForeground(red);
            calcButton.setEnabled(false);
        }
    }
}

From source file:vinci.project2.pkg1.View.java

private void numTest(JTextField fieldName, JLabel labelName) {
    String testS = fieldName.getText();

    if (testS.equals("")) {
        labelName.setForeground(red);/*from w  w w.  ja va2s .c o  m*/
        calcButton.setEnabled(false);
    } else {
        try {
            int testI = Integer.parseInt(fieldName.getText());

            if (testI > 0) {
                labelName.setForeground(black);
                calcButton.setEnabled(true);
            } else {
                labelName.setForeground(red);
                calcButton.setEnabled(false);
            }
        } catch (NumberFormatException e) {
            labelName.setForeground(red);
            calcButton.setEnabled(false);
        }
    }
}

From source file:vinci.project2.pkg1.View.java

private void tryTest(JTextField fieldName, JLabel labelName) {
    try {/*from  w w w .ja  v  a  2s  .c  o  m*/
        Double.parseDouble(fieldName.getText());
        labelName.setForeground(black);
        calcButton.setEnabled(true);
    } catch (NumberFormatException e) {
        labelName.setForeground(red);
        calcButton.setEnabled(false);
    }
}

From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfControlPanel.java

private PanelBuilder buildMainPanel(PanelBuilder builder, CellConstraints cc) {

    JLabel jLabelIdInTheApeEACCPF = new JLabel(this.labels.getString("eaccpf.control.idintheapeeaccpf"));
    builder.add(jLabelIdInTheApeEACCPF, cc.xy(1, rowNb));
    //extracted from dashboard implementation
    Random random = new Random();
    String value = "";
    //      String mainagencycode = (this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode()!=null && this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue()!=null )?this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue():"";
    if (this.eaccpf.getControl().getRecordId().getValue() == null
            || this.eaccpf.getControl().getRecordId().getValue().isEmpty()) {
        int fakeId = random.nextInt(1000000000);
        value = Integer.toString(fakeId);
        //         value = "eac_" + mainagencycode + "_" + Integer.toString(fakeId);
    } else {/*from  w  w  w. ja v  a2  s  . c  o m*/
        value = this.eaccpf.getControl().getRecordId().getValue();
    }
    JTextField jTextFieldIdInTheApeEACCPF = new JTextField(value);
    jTextFieldIdInTheApeEACCPF.setEnabled(false); //put like disabled, it's not editable
    builder.add(jTextFieldIdInTheApeEACCPF, cc.xy(3, rowNb));
    this.idAutogeneratedControl = jTextFieldIdInTheApeEACCPF.getText(); //It's not shown because field is autogenerated and it's not editabled (eaccpf object has no access to this value by form)
    setNextRow();

    JLabel jLabelLinkPersonResponsible = new JLabel(
            this.labels.getString("eaccpf.control.personinstitutionresponsiblefordescription"));
    builder.add(jLabelLinkPersonResponsible, cc.xy(1, rowNb));
    String content = "";
    if (StringUtils.isNotEmpty(responsible)) {
        content = responsible;
    } else if (this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() > 0
            && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent()
                    .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1)
                    .getAgent() != null
            && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent()
                    .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1)
                    .getAgent().getContent() != null
            && !this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent()
                    .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1)
                    .getAgent().getContent().isEmpty()) {
        content = this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent()
                .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1)
                .getAgent().getContent();
    } else {
        content = MAINTENANCE_AGENT_HUMAN;
    }

    JTextField jTextFieldPersonResponsible = new JTextField(content);
    builder.add(jTextFieldPersonResponsible, cc.xy(3, rowNb));
    this.personInstitutionResponsibleTextField = jTextFieldPersonResponsible;
    setNextRow();
    JLabel jLabelIdentifierForPersonResponsible = new JLabel(
            this.labels.getString("eaccpf.control.identifierofinstitutionresponsible") + "*");
    builder.add(jLabelIdentifierForPersonResponsible, cc.xy(1, rowNb));
    content = eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue() != null
            ? eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue()
            : "";
    JTextField jTextFieldIdentifierForPersonResponsible = new JTextField(content);
    builder.add(jTextFieldIdentifierForPersonResponsible, cc.xy(3, rowNb));
    this.idControl = jTextFieldIdentifierForPersonResponsible;
    setNextRow();

    if (StringUtils.isEmpty(content)) {
        builder.add(createErrorLabel(this.labels.getString("eaccpf.control.error.emptyidentifier")),
                cc.xyw(1, this.rowNb, 3));
        setNextRow();
    }
    if (this.eaccpf.getControl().getOtherRecordId().isEmpty()) {
        OtherRecordId newOtherRecordId = new OtherRecordId();
        newOtherRecordId.setLocalType(EacCpfPanel.LOCAL_TYPE_ORIGINAL);
        this.eaccpf.getControl().getOtherRecordId().add(newOtherRecordId);
    }

    List<OtherRecordId> otherRecordIds = this.eaccpf.getControl().getOtherRecordId();

    this.localIdentifierForInstitution = new ArrayList<JTextField>(otherRecordIds.size());
    this.listIdentifierType = new ArrayList<JTextField>(otherRecordIds.size());

    for (OtherRecordId otherRecordId : otherRecordIds) {
        // Create element.
        JTextField jTextFieldLocalIdentifierPersonResponsible = new JTextField(otherRecordId.getContent());
        JTextField jTextFieldIdentifierType = new JTextField(otherRecordId.getLocalType());

        // Add elements to the list.
        this.localIdentifierForInstitution.add(jTextFieldLocalIdentifierPersonResponsible);
        this.listIdentifierType.add(jTextFieldIdentifierType);
        builder.addLabel(this.labels.getString("eaccpf.control.otherRecordIdentifier"), cc.xy(1, this.rowNb));
        builder.add(jTextFieldLocalIdentifierPersonResponsible, cc.xy(3, this.rowNb));
        this.setNextRow();
    }

    JButton nextTabBtn = new ButtonTab(this.labels.getString("eaccpf.control.addlocalidentifier"));
    builder.add(nextTabBtn, cc.xy(1, this.rowNb));
    nextTabBtn.addActionListener(new AddLocalIdentifier(eaccpf, tabbedPane, model));
    setNextRow();

    builder.addLabel(this.labels.getString("eaccpf.control.usedlanguagesandscriptsfordescription"),
            cc.xyw(1, this.rowNb, 7));
    setNextRow();

    builder.addLabel(labels.getString("eaccpf.commons.select.language") + "*" + ":", cc.xy(1, rowNb));
    LanguageWithScript languageWithScript = new LanguageWithScript(firstLanguage, firstScript, labels);
    JComboBox<String> scriptBox = languageWithScript.getScriptBox();
    //fix for script part, it's not selecting values
    boolean found = false;
    int size = scriptBox.getModel().getSize();
    for (int i = 0; !found && i < size; i++) {
        String element = scriptBox.getModel().getElementAt(i);
        if (element != null && element.equalsIgnoreCase(firstScript)) {
            scriptBox.setSelectedIndex(i);
            found = true;
        }
    }
    //end fix for script part
    builder.add(languageWithScript.getLanguageBox(), cc.xy(3, rowNb));
    this.languageFirst = languageWithScript.getLanguageBox();
    builder.addLabel(labels.getString("eaccpf.control.selectascript") + "*" + ":", cc.xy(5, rowNb));
    builder.add(languageWithScript.getScriptBox(), cc.xy(7, rowNb));
    this.scriptFirst = languageWithScript.getScriptBox();
    this.languageWithScript = languageWithScript;
    setNextRow();

    return builder;
}

From source file:TextComponentTest.java

public TextComponentFrame() {
    setTitle("TextComponentTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final JTextField textField = new JTextField();
    final JPasswordField passwordField = new JPasswordField();

    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(2, 2));
    northPanel.add(new JLabel("User name: ", SwingConstants.RIGHT));
    northPanel.add(textField);//w w  w . j  ava2  s  . c o m
    northPanel.add(new JLabel("Password: ", SwingConstants.RIGHT));
    northPanel.add(passwordField);

    add(northPanel, BorderLayout.NORTH);

    final JTextArea textArea = new JTextArea(8, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);

    add(scrollPane, BorderLayout.CENTER);

    // add button to append text into the text area

    JPanel southPanel = new JPanel();

    JButton insertButton = new JButton("Insert");
    southPanel.add(insertButton);
    insertButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            textArea.append("User name: " + textField.getText() + " Password: "
                    + new String(passwordField.getPassword()) + "\n");
        }
    });

    add(southPanel, BorderLayout.SOUTH);

    // add a text area with scroll bars

}