public class MaskTextFilter extends Object implements UnaryOperator<TextFormatter.Change>
Mask to use as filter for TextFormatter.
TextField allowing only french phone numbers:
final TextField textField = new TextField();
final MaskCharacter[] mask = MaskBuilder.newBuilder()
.appendLiteral("+33 ")
.appendDigit('6')
.appendLiteral(" ")
.appendDigit(2)
.appendLiteral(" ")
.appendDigit(2)
.appendLiteral(" ")
.appendDigit(2)
.appendLiteral(" ")
.appendDigit(2)
.build();
textField.setTextFormatter(new TextFormatter<>(new MaskTextFilter(textField, false, mask)));
Default text will be "+33 6 00 00 00 00".MaskBuilder| Modifier and Type | Class and Description |
|---|---|
static interface |
MaskTextFilter.MaskCharacter
Mask character interface.
|
| Constructor and Description |
|---|
MaskTextFilter(MaskTextFilter.MaskCharacter... pMask) |
MaskTextFilter(TextInputControl input,
boolean setDefaultOnFocus,
MaskTextFilter.MaskCharacter... pMask) |
| Modifier and Type | Method and Description |
|---|---|
TextFormatter.Change |
apply(TextFormatter.Change c) |
void |
applyDefault(TextInputControl input) |
void |
install(TextInputControl input,
boolean setDefaultOnFocus) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitidentitypublic MaskTextFilter(MaskTextFilter.MaskCharacter... pMask)
pMask - the mask to usepublic MaskTextFilter(TextInputControl input, boolean setDefaultOnFocus, MaskTextFilter.MaskCharacter... pMask)
input - TextInputControl where the filter will be appliedsetDefaultOnFocus - true to set the default value when it gain the focus, otherwise the default value is immediately appliedpMask - the mask to usepublic void install(TextInputControl input, boolean setDefaultOnFocus)
input - TextInputControl where set the default valuesetDefaultOnFocus - true to set the default value when it gain the focus, otherwise the default value is immediately appliedpublic void applyDefault(TextInputControl input)
input - TextInputControl where set the default valuepublic TextFormatter.Change apply(TextFormatter.Change c)
apply in interface Function<TextFormatter.Change,TextFormatter.Change>Copyright © 2018. All rights reserved.