我基本上希望能够在我的 LWJGL/GLFW 线程启动后(和内部)启动一个新的 Javafx 窗口(阶段)。我基本上是这样做的:
Thread thread = new Thread(()->Platform.runLater(()->{
Stage stage = new Stage();
//Stage setup
stage.show();
}));
thread.start();
线程是我的游戏线程。
但它从未运行过,我在 Platform.runLater()
中尝试了 System.out.println()
只是为了检查它是否从未运行过。
为什么它永远不会运行,我该怎么做才能修复它?谢谢。
编辑:只是为了澄清线程肯定已经开始,如果我这样做的话:
Thread thread = new Thread(()->{
System.out.println("Before Platform.runLater()");
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
System.out.println("After Platform.runLater()");
});
输出:
Before Platform.runLater()
After Platform.runLater()
最佳答案
好的,我已经找到解决办法了!
如果您遇到所有场景都结束的情况,管理所有这些的线程就会逐渐消失。为防止这种情况发生,请在 Platform.runLater
之前添加此行:
Platform.setImplicitExit(false);
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
只要它在最后一个场景结束之前运行,它就会保持线程处于 Activity 状态,并且您不会遇到 runLater() 失败的问题!
关于Javafx Platform.runLater 从不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302837/