0

Current Implementation:

currently the user need to press the Enter key to generate an EventHandler to make my app do something with the input string in the TextField.

 textFieldSearchProductNumber.setOnKeyPressed((KeyEvent keyEvent) -> {
            if (keyEvent.getCode() == KeyCode.ENTER) {
                if (textFieldSearchProductNumber.getText().isEmpty()) {
                    // ... database query: string content of textFieldSearchProductNumber
                } 
        });

Target:

I would like to make the TextField generate an EventHandler as soon as the user stops the input (Maybe with help of a timer or any other recommendations)

  • further input to textfield is observed
    -> timer is reset to 500ms and textfield waits again for input
  • no further input to textfield with timer elapsed
    -> textfield pass its content to database search method

How would you go about in writing this sort of code?

Chiggiddi
  • 542
  • 1
  • 8
  • 26

1 Answers1

0

I have found this code snippet provided by jewelsea, which works great for my simple application (LINK). He also mentioned about using ReactFX for a more sophisticated solution (LINK)

PauseTransition pause = new PauseTransition(Duration.seconds(1));
textField.textProperty().addListener(
    (observable, oldValue, newValue) -> {
        pause.setOnFinished(event -> doSomething(newValue));
        pause.playFromStart();
    }
);
Chiggiddi
  • 542
  • 1
  • 8
  • 26