Class ElidingFilePathTextField

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

public class ElidingFilePathTextField extends PreviewTextField
PreviewTextField (JTextField) that has a preview that compresses / shortens the text in the field using rules that are tuned to preserve human readability of filename path info.

Longer directory names are truncated and modified to have a "..." suffix. When adjacent directory names have been reduced to just "...", they are combined into a single "...." (4-dot).

The first and last directory elements in the path are given preference and will be subject to shortening after interior directory name elements.

The final element in the path (filename) is always preserved.

If the preview of the path needs truncation, the full path will be temporarily appended to the the field's tool tip.

See Also:
  • Constructor Details

    • ElidingFilePathTextField

      public ElidingFilePathTextField()
      Creates a new ElidingFilePathTextField instance with no text.
    • ElidingFilePathTextField

      public ElidingFilePathTextField(String text)
      Creates a new ElidingFilePathTextField instance with specified text value.
      Parameters:
      text - string to assign as initial value of text field
    • ElidingFilePathTextField

      public ElidingFilePathTextField(String text, String hint)
      Creates a new ElidingFilePathTextField instance with specified text and hint values.
      Parameters:
      text - string to assign as initial value of text field
      hint - string to assign as the hint value that is shown when the field is blank
  • Method Details

    • isShortEnough

      protected boolean isShortEnough(String s, FontMetrics fm, int maxWidth)
    • getPreviewString

      protected String getPreviewString(String s, FontMetrics fm, int maxWidth)
      Description copied from class: PreviewTextField
      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).
      Specified by:
      getPreviewString in class PreviewTextField
      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