Java Utililty Methods JTextField

List of utility methods to do JTextField

Description

The list of methods to do JTextField are organized into topic(s).

Method

voidsetValue(JTextField f, String value)
For a JTextField, sets the value, validates, and repaints
f.setText(value);
f.validate();
f.repaint();
FileshowFileOpenDialogAndChangePrefs(String prefName, FileNameExtensionFilter fileNameExtensionFilter, JTextField textField, Class forClass, Component parent)
displays a file open dialog and copies the result to an edit field
JFileChooser fc = new JFileChooser();
fc.setFileFilter(fileNameExtensionFilter);
Preferences prefs2 = Preferences.userNodeForPackage(forClass);
String path = prefs2.get(prefName, null);
if (path != null) {
    fc.setCurrentDirectory(new File(path));
int result = fc.showOpenDialog(parent);
...
voidtextAreaChangeListener(JTextField a, final ChangeListener list)
Reroute all document changes to a change listener
a.getDocument().addDocumentListener(new DocumentListener() {
    public void change() {
        list.stateChanged(null);
    public void changedUpdate(DocumentEvent e) {
        change();
    public void removeUpdate(DocumentEvent e) {
...
voidtoUpperCase(JTextField field)
to Upper Case
String upper = field.getText();
field.setText(upper.toUpperCase());
voidtriggerTextField(JTextField textField, JCheckBox checkBox)
trigger Text Field
if (checkBox.isSelected()) {
    textField.setDisabledTextColor(Color.LIGHT_GRAY);
textField.setEnabled(!checkBox.isSelected());
StringupperText(JTextField text)
upper Text
String str = text.getText().toUpperCase();
text.setText(str);
return str;
doublevalidateJTextField(JTextField text, Component aThis)
Validates if the text field contains a number
try {
    double dev = validateValue(text.getText(), aThis);
    return dev;
} catch (NumberFormatException ex) {
    text.setText(null);
    throw ex;