TextField (and subclasses)
Swing components:
JTextField,
JFormattedTextField and
JPasswordField
Swing tutorial:
How to Use Text Fields,
Formatted Text Fields and
Password Fields
Following documentation describes TextField, but FormattedTextField and
PasswordField have same properties. Replace TextField.
with
FormattedTextField.
or PasswordField.
for those components.
Properties
For border properties see: FlatTextBorder
Colors
UI Key | Style Key since v2 | Description |
---|---|---|
TextField.foreground | foreground | text color if enabled (also used if not editable) |
TextField.inactiveForeground | disabledTextColor | text color if disabled |
TextField.placeholderForeground | placeholderForeground | placeholder text color, if text field is empty |
TextField.background | background | background color if enabled |
TextField.inactiveBackground | inactiveBackground | background color if not editable, but enabled |
TextField.disabledBackground | disabledBackground | background color if disabled |
TextField.focusedBackground | focusedBackground | background color if focused (optional) |
TextField.selectionForeground | selectedTextColor | selected text color |
TextField.selectionBackground | selectionColor | background color of selected text |
TextField.caretForeground | caretColor | (blinking) caret color |
PasswordField.capsLockIconColor | capsLockIconColor | "caps lock" icon color |
PasswordField.revealIconColor since v2 | - | reveal ("eye") icon color |
Sizes
UI Key | Style Key since v2 | Type | Description |
---|---|---|---|
TextField.margin | margin | Insets | margin space between the component border and the text |
Component.minimumWidth | minimumWidth | int | minimum width of component (in pixels) |
TextField.iconTextGap since v2 | iconTextGap | int | gap between leading or trailing icons and the text |
Other
UI Key | Style Key since v2 | Type | Description |
---|---|---|---|
TextField.font | font | Font | font used to render text |
TextField.border | border | Border | usually a FlatTextBorder |
TextField.caretBlinkRate | - | int | blink rate of the caret (in milliseconds) |
TextComponent.selectAllOnFocusPolicy | - | String | specifies whether all text is selected when the text component gains
focus (never , once or always ) |
TextComponent.selectAllOnMouseClick | - | boolean | if true , select all text when clicking with the mouse into the text
field (if enabled with TextComponent.selectAllOnFocusPolicy) |
PasswordField.echoChar | echoChar | character | character used for echoing |
PasswordField.showCapsLock | showCapsLock | boolean | if true , shows a "caps lock" icon if Caps Lock is on |
PasswordField.capsLockIcon | - | Icon | "caps lock" icon shown if Caps Lock is on |
PasswordField.showRevealButton since v2 | showRevealButton | boolean | if true , shows a reveal ("eye") toggle button that makes the password
visible if selected |
PasswordField.revealIcon since v2 | - | Icon | reveal ("eye") icon shown if PasswordField.showRevealButton is true |
Styling since v2
Following properties are only available via styling (not in UI defaults, but has likewise client properties).
Style Key | Type | Description | Client Property |
---|---|---|---|
leadingIcon | Icon | an icon that will be placed at the leading edge of the text field | JTextField.leadingIcon |
trailingIcon | Icon | an icon that will be placed at the trailing edge of the text field | JTextField.trailingIcon |
showClearButton | boolean | if true , show a "clear" (or "cancel") button on the trailing side if
the text field is not empty, editable and enabled |
JTextField.showClearButton |