Class HintTextField

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

public class HintTextField extends JTextField implements FocusListener
A class extending a JTextField that can display a 'ghost' text prompt in the field when it is empty. Hint display by default is whenever the field has no text, but hint display can be limited to only when the field has focus.
See Also:
  • Constructor Details Link icon

    • HintTextField Link icon

      public HintTextField(int length, String hint)
      Create a new HintTextField with a length and specified hint
      Parameters:
      length - Field Length
      hint - Hint text
    • HintTextField Link icon

      public HintTextField(String hint)
      Create a new HintTextField with a specified hint
      Parameters:
      hint - Hint text
  • Method Details Link icon

    • paint Link icon

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • focusCheck Link icon

      protected boolean focusCheck()
    • focusGained Link icon

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

      public void focusLost(FocusEvent e)
      Specified by:
      focusLost in interface FocusListener
    • isFocusOnly Link icon

      public boolean isFocusOnly()
      Does this field only display a hint when it has the focus?
      Returns:
      Display hint only with focus
    • setFocusOnly Link icon

      public void setFocusOnly(boolean focusOnly)
      Set whether or not the hint should be displayed if the field does not have focus
      Parameters:
      focusOnly - If true, hint will only be displayed if field has focus
    • getHint Link icon

      public String getHint()
      Return the current hint text
      Returns:
      Hint text
    • setHint Link icon

      public void setHint(String hint)
      Set the Hint text
      Parameters:
      hint - Hint text