Class PreviewTextField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
ElidingFilePathTextField

public abstract class PreviewTextField extends HintTextField
Abstract base class for text fields that can show a preview of a modified version of their text when it does not have focus.

The tool tip of the field is updated to include the full value of the field if the preview was truncated during painting. Override getPreviewToolTipAdditionalText() to control what text is added to the tool tip in those cases.

NOTE: using an ending </HTML> tag in a tool tip string is not recommended as it will defeat PreviewTextField's updated information from being displayed to the user.

See Also:
  • Constructor Details

  • Method Details

    • getPreviewString

      protected abstract String getPreviewString(String s, FontMetrics fm, int maxWidth)
      Generates a modified version of the specified string in a usage-specific manner. The returned string will be used as a preview of the text field's value (when the text field does not have focus).
      Parameters:
      s - string to base the preview value on
      fm - FontMetrics to use when measuring the length of the string
      maxWidth - maximum desired width of the string that should be returned by this method
      Returns:
      shortened version of parameter s
    • paintComponent

      public void paintComponent(Graphics g)
      Description copied from class: HintTextField
      Overridden to paint the hint text over the field when it's empty
      Overrides:
      paintComponent in class HintTextField
    • getPreviewToolTipAdditionalText

      protected String getPreviewToolTipAdditionalText()
      Returns string that should be appended to the tool tip when the text field preview has been truncated. Defaults to the plain text of the field..
      Returns:
      string that should be appended to the tool tip when the text field preview has been truncated. Defaults to the plain text of the field.
    • setText

      public void setText(String text)
      Description copied from class: HintTextField
      Overridden to check the field validity when text changes
      Overrides:
      setText in class HintTextField
      Parameters:
      text - the text to fill
    • setToolTipText

      public void setToolTipText(String text)
      Overrides:
      setToolTipText in class JComponent