Answers for "javafx how to set textfield to accept only numbers"

2

javafx textfield only numbers

// force the field to be numeric only
textField.textProperty().addListener(new ChangeListener<String>() {
    @Override
    public void changed(ObservableValue<? extends String> observable, String oldValue, 
        String newValue) {
        if (!newValue.matches("\d*")) {
            textField.setText(newValue.replaceAll("[^\d]", ""));
        }
    }
});
Posted by: Guest on October-17-2020

Code answers related to "javafx how to set textfield to accept only numbers"

Browse Popular Code Answers by Language