在特定时间后自动生成 EventHandler,无需用户在 TextField 中输入 (JavaFX)

Automatically generate EventHandler after a specific time without user input in TextField (JavaFX)

当前实施:

目前,用户需要按 Enter 键 来生成事件处理程序,使我的应用程序对 TextField 中的输入字符串执行某些操作。

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

目标:

我想让 TextField 在用户停止输入时立即生成事件处理程序(可能借助计时器或任何其他建议)

您将如何编写此类代码?

我找到了 jewelsea, which works great for my simple application (LINK 提供的这段代码片段。 他还提到将 ReactFX 用于更复杂的解决方案 (LINK)

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