📜  javafx textfield only numbers - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:02.656000             🧑  作者: Mango

代码示例1
// force the field to be numeric only
textField.textProperty().addListener(new ChangeListener() {
    @Override
    public void changed(ObservableValue observable, String oldValue, 
        String newValue) {
        if (!newValue.matches("\\d*")) {
            textField.setText(newValue.replaceAll("[^\\d]", ""));
        }
    }
});