0

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.

5
  • 6
    I 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 helps Commented Jun 22, 2017 at 15:32
  • how to access the field method from fxml? Commented Jun 22, 2017 at 15:42
  • Here's something that might help you that i saw. stackoverflow.com/a/30935675/8029396 Commented Jun 22, 2017 at 15:43
  • 1
    There may be an onTextChanged method Commented Jun 22, 2017 at 15:43
  • Use this and check the length of the new value. Commented Jun 22, 2017 at 15:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.