Class VerifiableTextField

All Implemented Interfaces:
FocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Scrollable, SwingConstants

public class VerifiableTextField extends JTextField implements FocusListener
This is an extension of the JTextField that includes the capacity for DataVerifier objects to be added. These verifiers will be checked when the component loses focus and if any fail, the background of the field will be turned red and the tool tip updated with information on what verifier was failed.
Since:
3/14/14 1:08 PM
See Also:
  • Constructor Details

  • Method Details

    • isSelectAllTextOnGotFocus

      @Deprecated(since="0.51.0", forRemoval=true) public boolean isSelectAllTextOnGotFocus()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      TRUE if all the text in this control will be automatically selected when it receives the focus.
    • setSelectAllTextOnGotFocus

      public void setSelectAllTextOnGotFocus(boolean selectAllTextOnGotFocus)
      Parameters:
      selectAllTextOnGotFocus - Set TRUE if all the text in this control will be automatically selected when it receives the focus.
    • isTextNullOrEmpty

      public boolean isTextNullOrEmpty()
      Returns:
      TRUE if the field's text value is NULL or an empty String.
    • isTextNumeric

      public boolean isTextNumeric()
      Returns:
      TRUE if the field's text value is a valid number.
    • isRequired

      public boolean isRequired()
      Returns:
      TRUE if this field is not allowed to be null or empty.
    • setRequired

      public void setRequired(boolean required)
      Marks this text field as required/unrequired and sets up/removes a VerifyNotNullOrEmpty verifier. Also sets the background color blue if it is required.
      Parameters:
      required - TRUE if this field is required to have data.
    • focusGained

      public void focusGained(FocusEvent e)
      Specified by:
      focusGained in interface FocusListener
    • focusLost

      public void focusLost(FocusEvent e)
      Specified by:
      focusLost in interface FocusListener
    • addVerifier

      public void addVerifier(DataVerifier verifier)
      Adds a new DataVerifier to validate this field's data.
      Parameters:
      verifier - The new DataVerifier to be added.
    • removeVerifier

      @Deprecated(since="0.51.0", forRemoval=true) public void removeVerifier(DataVerifier verifier)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Removes the given DataVerifier from this field.
      Parameters:
      verifier - The DataVerifier to be removed.
    • verifyTextS

      public String verifyTextS()
      Compares the text field's value to the list of DataVerifier objects to ensure the validity of the data. If the text value passes all validation checks, a NULL value will be returned. Otherwise, a description of the failed validation will be returned. Does not verify if the field is disabled.
      Returns:
      NULL if the text in the field is valid. A description of the failure otherwise.
    • verifyText

      public boolean verifyText()
      Compares the text field's value to the list of DataVerifier objects to ensure the validity of the data.
      Returns:
      true if the text in the field is valid.
    • getAsInt

      public Integer getAsInt()
    • getOldToolTip

      @Deprecated(since="0.51.0", forRemoval=true) public String getOldToolTip()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setOldToolTip

      public void setOldToolTip(String oldToolTip)
    • getInvalidColor

      public static Color getInvalidColor()
      Returns an "invalid background" color. It is mixed from the GUIPreferences WarningColor and the UIManager text field background color.
    • getMaximumSize

      public Dimension getMaximumSize()
      Overrides:
      getMaximumSize in class JComponent