Search code examples
javamultithreadingjavafx-2javafx-8jnativehook

JavaFx: bring stage to focus on keypress


I'm trying to bring my window to focus on a keypress (using jnativehook), but getting this error:

java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = JNativeHook Dispatch Thread` exception.

It seems like I can't change the UI from the hook's thread.

Is there any way, to get the stage to the foreground? I'm open to using other key hooks, if necessary.


Solution

  • As James_D suggested, the Platform.runLater(...) works. The issue, that the window still wasn't in foreground, was another problem, which was fixed with a setIconified true-false combo.