Class TextComponents


  • public final class TextComponents
    extends Object
    A utility class for JTextComponents.
    • Field Detail

      • DIMENSION_TEXT_FIELD_SQUARE

        public static final Dimension DIMENSION_TEXT_FIELD_SQUARE
        A square dimension which sides are the same as the preferred height of a JTextField. This comes in handy for example when adding "..." lookup buttons next to text fields.
    • Method Detail

      • maximumLength

        public static void maximumLength​(Document document,
                                         int maximumLength)
        Sets the maximum length for the given document, supports SizedDocument and AbstractDocument
        Parameters:
        document - the document
        maximumLength - the maximum string length
      • upperCase

        public static void upperCase​(Document document)
        Makes the given document convert all lower case input to upper case, supports SizedDocument and AbstractDocument
        Parameters:
        document - the document
      • lowerCase

        public static void lowerCase​(Document document)
        Makes the given document convert all upper case input to lower case, supports SizedDocument and AbstractDocument
        Parameters:
        document - the document
      • selectAllOnFocusGained

        public static <T extends JTextComponent> T selectAllOnFocusGained​(T textComponent)
        Selects all text in the given component when it gains focus and clears the selection when focus is lost
        Type Parameters:
        T - the component type
        Parameters:
        textComponent - the text component
        Returns:
        the component
      • preferredTextFieldSize

        public static Dimension preferredTextFieldSize()
        Returns:
        the preferred size of a JTextField
      • preferredTextFieldHeight

        public static int preferredTextFieldHeight()
        Returns:
        the preferred height of a JTextField