📅  最后修改于: 2022-03-11 14:55:02.656000             🧑  作者: Mango
// force the field to be numeric only
textField.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable, String oldValue,
String newValue) {
if (!newValue.matches("\\d*")) {
textField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});