Javafx Platform.runLater从未运行过 [英] Javafx Platform.runLater never running

查看:568
本文介绍了Javafx Platform.runLater从未运行过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上希望能够在我的LWJGL / GLFW线程启动后(和内部)启动一个新的Javafx窗口(阶段)。我基本上是这样做的:

I basically want to be able to launch a new Javafx window (stage) after (and inside) my LWJGL/GLFW thread starts. I am basically doing:

Thread thread = new Thread(()->Platform.runLater(()->{
    Stage stage = new Stage();
    //Stage setup
    stage.show();
}));
thread.start();

线程是我的游戏线程。
但是它从未运行过,我在 Platform.runLater() System.out.println() $ c>只是检查它永远不会运行。

thread being my game thread. But it never runs and I've tried a System.out.println() inside Platform.runLater() just to check it never runs.

为什么它永远不会运行,我该怎么做才能修复它?谢谢。

Why does it never run and what can I do to fix it? Thanks.

编辑:只是为了澄清线程已经明确开始,如果我这样做了:

Just to clarify that the thread has definitely started and whatnot, if I do:

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()


推荐答案

好的,我找到了解决方法!

Ok, I have found the solution to this!

如果遇到所有场景结束的任何情况,管理所有这一切的线程只会逐渐消失。要防止这种情况发生,请在 Platform.runLater 之前添加此行:

If you run into any situation where all of your scenes end, the thread managing all of this will just peter out. To prevent this from happening, add this line before Platform.runLater:

Platform.setImplicitExit(false);
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));

只要在最后一个场景结束之前运行,它就会保持线程活着,你会没有遇到runLater()失败的问题!

So long as this runs before the last scene ends, it will keep the thread alive, and you will not run into the problem of runLater() failing!

这篇关于Javafx Platform.runLater从未运行过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆