A simple class for some basic TextField validations, which uses TextFormatter introduced in JavaFX 8u40
textField.setTextFormatter(new TextFieldValidator(ValidationModus.MAX_INTEGERS, 4).getFormatter());
or instantiate it in a fxml file, and apply it to a CustomTextField with the according properties.
<fx:define>
<TextFieldValidator fx:id="validator" modus="MAX_INTEGERS" countOf="4"/>
</fx:define>
<CustomTextField validator="$validator" />
public class CustomTextField {
private TextField textField;
public CustomTextField(@NamedArg("validator") TextFieldValidator validator) {
textField.setTextFormatter(validator.getFormatter());
}
}
When using TextFormatter, any listener attached to textField.textProperty() won't see changes that get rejected by the TextFormatter
Hi,
Is there any Copyright License?
I wanted to use your TextfieldValidator in an non profit university Software project.
Its use would be in the configuration Editor of a small JavaFx based game.