java.lang.Object
javafx.scene.control.TextFormatter<String>
atlantafx.base.util.MaskTextFormatter
A
TextFormatter
that can restrict the user input by applying a position-based mask.
It works for the editing cases when the input string has a fixed length and each character
can be restricted based on its position.Input Mask
You can specify an input mask either as a string of the predefined characters or as a list ofMaskChar
, including your own implementation if you're not satisfied with the default
SimpleMaskChar
, e.g. if you want to override the placeholder character.
The pre-defined mask characters are:
- A - ASCII alphabetic character:
[a-zA-Z]
. - N - ASCII alphanumeric character:
[a-zA-Z0-9]
. - X - any character except spaces.
- H - hexadecimal character:
[a-fA-F0-9]
. - D - any digit except zero:
[1-9]
. - 9 - any digit required:
[0-9]
. - 8..1 - any digit from 0 to that number, respectively.
- 0 - zero only.
Behavior
AnyTextField
with MaskTextFormatter
applied shows a placeholder
mask by default. This is basically the input mask with all mask characters replaced
with the MaskChar.getPlaceholder()
character.
The behavior changes if you set the TextInputControl.promptTextProperty()
.
In that case placeholder mask is only displayed when TextField
gets focus and
will be hidden after focus lost. So, the placeholder mask is always displayed when focus
is set to the TextField
.
You can replace the placeholder mask with any sensible default simply by changing initial
TextField
text to any string that is valid against the input mask.
The caret will be positioned before the first not fixed character (see MaskChar.isFixed()
)
starting from the beginning of the input mask.
Validation
Validation is out of theMaskTextFormatter
scope. E.g. if one can use "29:59"
to restrict time picker input then "27:30"
would be a valid input, but obviously an
invalid time. Moreover, remember that partial input like this "22:_9"
is also possible.
Input mask is supposed to assist and guide user input, but can barely cancel the validation
completely.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class javafx.scene.control.TextFormatter
javafx.scene.control.TextFormatter.Change
-
Property Summary
Properties inherited from class javafx.scene.control.TextFormatter
value
-
Field Summary
FieldsFields inherited from class javafx.scene.control.TextFormatter
IDENTITY_STRING_CONVERTER
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
-
Method Summary
Modifier and TypeMethodDescriptionstatic MaskTextFormatter
Creates a new mask text formatter with the provided string input mask and applies itself to the specified text field.static MaskTextFormatter
Creates a new mask text formatter with the provided input mask and applies itself to the specified text field.protected static String
createPlaceholderMask
(String inputMask) protected static String
createPlaceholderMask
(List<MaskChar> mask) static javafx.scene.control.TextField
createTextField
(String mask) Creates a new text field with the provided string input mask.static javafx.scene.control.TextField
createTextField
(List<MaskChar> mask) Creates a new text field with the provided input mask.fromString
(String inputMask) Methods inherited from class javafx.scene.control.TextFormatter
getFilter, getValue, getValueConverter, setValue, valueProperty
-
Field Details
-
filter
-
-
Constructor Details
-
MaskTextFormatter
-
-
Method Details
-
createTextField
Creates a new text field with the provided string input mask. -
createTextField
-
create
Creates a new mask text formatter with the provided string input mask and applies itself to the specified text field. -
create
Creates a new mask text formatter with the provided input mask and applies itself to the specified text field. -
createPlaceholderMask
-
createPlaceholderMask
-
fromString
-