I need to insert a number field into my UI. So I need to check the key events on a text field in order to check whether the input character is a number. I created a class by
Applying the following way it is possible to make TextField into NumberField but this way it will not filter the keyboard input instantly... but if you focus out the field then you will see the result. You may use this for basic numeric input field validation. I am giving here some example... It may help someone :)
// It will show the number with comma ie. 64,568,455
TextField numberField = new TextField();
numberField.setTextFormatter(new TextFormatter<>(new NumberStringConverter()));
// It will show the integer number ie. 64568455
TextField integerField = new TextField();
integerField.setTextFormatter(new TextFormatter<>(new IntegerStringConverter()));
// It will ensure the float format ie. 2635.0
TextField floatField = new TextField();
floatField.setTextFormatter(new TextFormatter<>(new FloatStringConverter()));