JavaFx:让舞台聚焦于按键
我试图使我的窗口集中在按键上(使用jnativehook),但出现以下错误:JavaFx:让舞台聚焦于按键,java,multithreading,javafx-2,javafx-8,jnativehook,Java,Multithreading,Javafx 2,Javafx 8,Jnativehook,我试图使我的窗口集中在按键上(使用jnativehook),但出现以下错误: java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = JNativeHook Dispatch Thread` exception. 看起来我无法从钩子的线程更改UI 有没有办法把舞台移到前台?如果有必要,我愿意使用其他键挂钩。正如建议的那样,平台.runLater(
java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = JNativeHook Dispatch Thread` exception.
看起来我无法从钩子的线程更改UI
有没有办法把舞台移到前台?如果有必要,我愿意使用其他键挂钩。正如建议的那样,
平台.runLater(…)
可以工作。窗口仍然不在前台的问题是另一个问题,通过setIconified true-false组合修复了该问题。只需将调用包装到Platform.runLater(…)
。在本论坛中搜索“java.lang.IllegalStateException:不在FX应用程序线程上”。谢谢!runLater示例之一正在工作,它更新标签的文本。但是调用primaryStage.toFront()时,主窗口仍在backgound中;如果需要包装所有内容,则可能需要在此处使用自定义调度程序: