I was browsing here on StackOverflow a solution to a problem: essentially I want the TextField to limit user input to just numeric values/ integers. I have found an answer that mentions a listener:
public class CubeController {
public Label areaCube, volumeCube;
public TextField insertValue;
public void checkValue(){
insertValue.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d{0,7}([\\.]\\d{0,4})?")) {
insertValue.setText(oldValue);
}
}
});}
}
I have tried to implement it on a TextField but with no success. (Initialized in an FXML file) What exactly is a Listener, and why it seems to not have effect on my TextField ? Thanks to everybody.
<TextField onAction="#checkValue" fx:id="insertValue" layoutX="269.0" layoutY="178.0" promptText="Insert edge measure" />