Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFx:让舞台聚焦于按键_Java_Multithreading_Javafx 2_Javafx 8_Jnativehook - Fatal编程技术网

JavaFx:让舞台聚焦于按键

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(

我试图使我的窗口集中在按键上(使用jnativehook),但出现以下错误:

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中;如果需要包装所有内容,则可能需要在此处使用自定义调度程序: