1

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.

sirgyula
  • 43
  • 7
  • 2
    Just wrap the call in `Platform.runLater(...)`. Search this forum for "java.lang.IllegalStateException: not on FX Application Thread". – James_D Aug 08 '17 at 12:05
  • Thanks! One of the runLater sample is working, it updates the text of a label. But the main window is still in the backgound, when calling primaryStage.toFront(); – sirgyula Aug 08 '17 at 12:34
  • Possible duplicate of [Making games with JNativeHook](https://stackoverflow.com/questions/45403575/making-games-with-jnativehook) – Alex Barker Aug 08 '17 at 17:13

1 Answers1

1

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.

sirgyula
  • 43
  • 7
  • If you need to wrap everything, you may want to use the custom dispatcher here: https://stackoverflow.com/a/45423466/773849 – Alex Barker Aug 16 '17 at 17:29