List of utility methods to do JTextField
boolean | isActiveComponents(JTextField... textFields) is Active Components for (JTextField textField : textFields) if (textField.isEnabled()) return textField.isEnabled(); return false; |
boolean | isEmptyStr(javax.swing.JTextField input) Check if the JTextField input is empty return "".equals(input.getText().trim()); |
boolean | isInHighlight(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(); |
boolean | isJTextFieldNotEmpty(javax.swing.JTextField field) is J Text Field Not Empty return !(field.getText().trim().isEmpty());
|
boolean | isTelpValid(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 { ... |
boolean | IsTextFieldEmpty(javax.swing.JTextField tf) Is Text Field Empty return (tf.getText().length() == 0);
|
boolean | isTextFieldModified(JTextField textField, String originalValue) is Text Field Modified return (textField.getText() != null ? !textField.getText().equals(originalValue) : originalValue != null);
|
int | newIntegerValue(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; ... |
void | onTextFieldChange(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(); ... |
int | parseTextFieldInteger(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; ... |