2017-08-08 51 views
1

我試圖把我的窗口集中在(使用jnativehook)一個按鍵,但得到這個錯誤:了JavaFx:把階段重點按鍵

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

好像我不能改變來自鉤子線程的UI。

有沒有辦法讓舞臺到達前臺?如有必要,我願意使用其他鑰匙扣。

+2

只需將調用包裝在'Platform.runLater(...)'中。在此論壇中搜索「java.lang.IllegalStateException:not on FX Application Thread」。 –

+0

謝謝!其中一個runLater示例正在運行,它會更新標籤的文本。但是當調用primaryStage.toFront()時,主窗口仍然在背景中。 – sirgyula

+0

[使用JNativeHook製作遊戲]可能的副本(https://stackoverflow.com/questions/45403575/making-games-with-jnativehook) –

回答

1

由於James_D建議,Platform.runLater(...)的作品。這個問題,窗口仍然不在前臺,是另一個問題,這是一個setIconified真假組合。

+0

如果您需要包裝所有內容,您可能需要在此處使用自定義調度程序:https ://stackoverflow.com/a/45423466/773849 –