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

booleanisActiveComponents(JTextField... textFields)
is Active Components
for (JTextField textField : textFields)
    if (textField.isEnabled())
        return textField.isEnabled();
return false;
booleanisEmptyStr(javax.swing.JTextField input)
Check if the JTextField input is empty
return "".equals(input.getText().trim());
booleanisInHighlight(MouseEvent e, JTextField label, Highlighter h)
Returns true if the given mouse event occurred within a highlight h on label.
Highlight[] hls = h.getHighlights();
if (hls == null || hls.length == 0)
    return false;
Highlight hl = hls[0];
FontMetrics fm = label.getFontMetrics(label.getFont());
int offset = getCharOffset(fm, label.getText(), e.getX());
return hl.getStartOffset() <= offset && offset < hl.getEndOffset();
booleanisJTextFieldNotEmpty(javax.swing.JTextField field)
is J Text Field Not Empty
return !(field.getText().trim().isEmpty());
booleanisTelpValid(JTextField field)
is Telp Valid
boolean valid;
String inputTelp = field.getText();
String exp = "(^0[1-9]).{9,}";
Pattern p = Pattern.compile(exp);
Matcher m = p.matcher(inputTelp);
if (m.matches()) {
    return valid = true;
} else {
...
booleanIsTextFieldEmpty(javax.swing.JTextField tf)
Is Text Field Empty
return (tf.getText().length() == 0);
booleanisTextFieldModified(JTextField textField, String originalValue)
is Text Field Modified
return (textField.getText() != null ? !textField.getText().equals(originalValue) : originalValue != null);
intnewIntegerValue(JTextField text, int oldValue)
Bepaal de nieuwe integer waarde voor een textfield Als het tekstveld een geldig getal bevat, wordt deze waarde geretourneerd anders de oude waarde
int value;
try {
    value = Integer.parseInt(text.getText());
} catch (Exception e) {
    value = oldValue;
text.setText(Integer.toString(value));
return value;
...
voidonTextFieldChange(JTextField field, final Runnable task)
on Text Field Change
field.getDocument().addDocumentListener(new DocumentListener() {
    @Override
    public void insertUpdate(DocumentEvent e) {
        task.run();
    @Override
    public void removeUpdate(DocumentEvent e) {
        task.run();
...
intparseTextFieldInteger(JTextField field)
Returns the integer value of a JTextField.
String fText = field.getText();
if (fText.length() == 0) {
    return 0;
} else {
    try {
        return Integer.parseInt(fText);
    } catch (NumberFormatException e) {
        return 0;
...