i tried limited my javafx TextField for letters and max length. I've done it many times before and i always used the same method but this time i had error.
This is my code:
nameTextField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(final ObservableValue<? extends String> ov, final String oldValue, final String newValue) {
if (nameTextField.getText().length() > 30) {
String s = nameTextField.getText().substring(0, 30);
nameTextField.setText(s);
}
if (!newValue.matches("\\sa-zA-Z")) {
nameTextField.setText(newValue.replaceAll("[^\\sa-zA-Z]", ""));
}
}
});
When i use only limit for maxlength it's work correct and when i use only limit for type of letters also work correct. But when i use both limit on one field don't works correct.
Limit for type of letters work correct but when i try put more than 30 letter i have "Exception in thread "JavaFX Application Thread" java.lang.StackOverflowError"
at this line
nameTextField.setText(newValue.replaceAll("[^\\sa-zA-Z]", ""));