I need to check user input in realtime. So when the user has entered more than for example 40 characters, he will be sent to the next line. I tried to use getText method in onKeyReleased method, but when the user hold the key, it can enter more than 40 characters. Sorry, maybe the explanation is not good enough.
-
6I recommend making it into a property and then add a listener to the property, then whenever it changes you can check if the length of input is > 40, then you can jump them to the next line. Hope that helpsZeldaZach– ZeldaZach2017-06-22 15:32:22 +00:00Commented Jun 22, 2017 at 15:32
-
how to access the field method from fxml?artek– artek2017-06-22 15:42:59 +00:00Commented Jun 22, 2017 at 15:42
-
Here's something that might help you that i saw. stackoverflow.com/a/30935675/8029396Oron Zimmer– Oron Zimmer2017-06-22 15:43:24 +00:00Commented Jun 22, 2017 at 15:43
-
1There may be an onTextChanged methodSedJ601– SedJ6012017-06-22 15:43:37 +00:00Commented Jun 22, 2017 at 15:43
-
Use this and check the length of the new value.SedJ601– SedJ6012017-06-22 15:45:42 +00:00Commented Jun 22, 2017 at 15:45
Add a comment
|
1 Answer
Maybe what you are looking is something like that:
/* [Code...] */
@FXML
private void initialize() {
firstField.textProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.length() > 40)
secondField.requestFocus();
});
}
/* [Code..] */
Need to do the changes on the Controller class. As Sendrick suggested on the link this.