Module is.codion.swing.common.ui
Class TextComponents
- java.lang.Object
-
- is.codion.swing.common.ui.component.text.TextComponents
-
public final class TextComponents extends Object
A utility class for JTextComponents.
-
-
Field Summary
Fields Modifier and Type Field Description static Dimension
DIMENSION_TEXT_FIELD_SQUARE
A square dimension which sides are the same as the preferred height of a JTextField.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
lowerCase(Document document)
Makes the given document convert all upper case input to lower case, supportsSizedDocument
andAbstractDocument
static void
maximumLength(Document document, int maximumLength)
Sets the maximum length for the given document, supportsSizedDocument
andAbstractDocument
static int
preferredTextFieldHeight()
static Dimension
preferredTextFieldSize()
static <T extends JTextComponent>
TselectAllOnFocusGained(T textComponent)
Selects all text in the given component when it gains focus and clears the selection when focus is loststatic <T extends JTextComponent>
TselectNoneOnFocusGained(T textComponent)
Reverts the functionality added viaselectAllOnFocusGained(JTextComponent)
.static void
upperCase(Document document)
Makes the given document convert all lower case input to upper case, supportsSizedDocument
andAbstractDocument
-
-
-
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, supportsSizedDocument
andAbstractDocument
- Parameters:
document
- the documentmaximumLength
- the maximum string length
-
upperCase
public static void upperCase(Document document)
Makes the given document convert all lower case input to upper case, supportsSizedDocument
andAbstractDocument
- Parameters:
document
- the document
-
lowerCase
public static void lowerCase(Document document)
Makes the given document convert all upper case input to lower case, supportsSizedDocument
andAbstractDocument
- 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
-
selectNoneOnFocusGained
public static <T extends JTextComponent> T selectNoneOnFocusGained(T textComponent)
Reverts the functionality added viaselectAllOnFocusGained(JTextComponent)
.- Type Parameters:
T
- the component type- Parameters:
textComponent
- the text component- Returns:
- the text component
- See Also:
selectAllOnFocusGained(JTextComponent)
-
preferredTextFieldSize
public static Dimension preferredTextFieldSize()
- Returns:
- the preferred size of a JTextField
-
preferredTextFieldHeight
public static int preferredTextFieldHeight()
- Returns:
- the preferred height of a JTextField
-
-