Class Placeholder

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

public class Placeholder extends JLabel implements FocusListener, DocumentListener
Source: https://tips4java.wordpress.com/2009/11/29/text-prompt/ The TextPrompt class will display a prompt over top of a text component when the Document of the text field is empty. The Show property is used to determine the visibility of the prompt.

The Font and foreground Color of the prompt will default to those properties of the parent text component. You are free to change the properties after class construction.

See Also:
  • Constructor Details

  • Method Details

    • changeAlpha

      public void changeAlpha(float alpha)
      Convenience method to change the alpha value of the current foreground Color to the specific value.
      Parameters:
      alpha - value in the range of 0 - 1.0.
    • changeAlpha

      public void changeAlpha(int alpha)
      Convenience method to change the alpha value of the current foreground Color to the specific value.
      Parameters:
      alpha - value in the range of 0 - 255.
    • changeStyle

      public void changeStyle(int style)
      Convenience method to change the style of the current Font. The style values are found in the Font class. Common values might be: Font.BOLD, Font.ITALIC and Font.BOLD + Font.ITALIC.
      Parameters:
      style - value representing the the new style of the Font.
    • getShow

      public Placeholder.Show getShow()
      Get the Show property
      Returns:
      the Show property.
    • setShow

      public void setShow(Placeholder.Show show)
      Set the prompt Show property to control when the prompt is shown. Valid values are:

      Show.ALWAYS (default) - always show the prompt Show.Focus_GAINED - show the prompt when the component gains focus (and hide the prompt when focus is lost) Show.Focus_LOST - show the prompt when the component loses focus (and hide the prompt when focus is gained)

      Parameters:
      show - a valid Show enum
    • getShowPromptOnce

      public boolean getShowPromptOnce()
      Get the showPromptOnce property
      Returns:
      the showPromptOnce property.
    • setShowPromptOnce

      public void setShowPromptOnce(boolean showPromptOnce)
      Show the prompt once. Once the component has gained/lost focus once, the prompt will not be shown again.
      Parameters:
      showPromptOnce - when true the prompt will only be shown once, otherwise it will be shown repeatedly.
    • focusGained

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

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

      public void insertUpdate(DocumentEvent e)
      Specified by:
      insertUpdate in interface DocumentListener
    • removeUpdate

      public void removeUpdate(DocumentEvent e)
      Specified by:
      removeUpdate in interface DocumentListener
    • changedUpdate

      public void changedUpdate(DocumentEvent e)
      Specified by:
      changedUpdate in interface DocumentListener