【问题标题】:JavaFx: bring stage to focus on keypressJavaFx:将舞台集中在按键上
【发布时间】:2017-08-08 11:53:03
【问题描述】:

我正试图让我的窗口专注于按键(使用 jnativehook),但收到此错误:

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

似乎我无法从钩子的线程中更改 UI。

有什么方法可以让舞台出现在前台?如有必要,我愿意使用其他关键挂钩。

【问题讨论】:

  • 只需将电话转入Platform.runLater(...)。在此论坛中搜索“java.lang.IllegalStateException: not on FX Application Thread”。
  • 谢谢! runLater 示例之一正在工作,它更新标签的文本。但是调用primaryStage.toFront();时,主窗口仍然在后台;

标签: java multithreading javafx-2 javafx-8 jnativehook


【解决方案1】:

正如James_D 建议的那样,Platform.runLater(...) 有效。窗口仍然不在前台的问题是另一个问题,已通过 setIconified true-false 组合修复。

【讨论】:

猜你喜欢
  • 2015-05-21
  • 2014-08-06
  • 2014-08-07
  • 2013-12-04
  • 2013-05-14
  • 2018-09-06
  • 1970-01-01
  • 2017-12-17
  • 2016-12-13
相关资源
最近更新 更多