简体   繁体   English

网站重新加载后的JavaFX Platform.runLater()

[英]JavaFX Platform.runLater() after site reload

I am writing an Java Applet using JavaFX embedded in Swing. 我正在使用嵌入在Swing中的JavaFX编写Java Applet。 Users are able to start a Swing-GUI with JavaFX components using JFXPanel with the following code: 用户可以使用JFXPanel通过以下代码使用JavaFX组件启动Swing-GUI:

group = AccessController.doPrivileged(new ProxyNewGroup());
fxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
    public void run() {
        /* Create some objects and add them to group */
        ...
        Scene scene = new Scene(group);
        fxPanel.setScene(scene);
    }
};
jFrame.add(fxPanel);

When the Applet starts first the user can create the GUI element and close it. 当Applet首先启动时,用户可以创建GUI元素并将其关闭。 Later he can recreate. 以后他可以重新创建。 To do so I need to hold an invisible JFrame containig a JFXPanel the whole runtime in memory, that I never use, because I read somewhere that otherwise the JavaFX-Application-Thread is stopped. 为此,我需要在整个运行时将一个不可见的JFrame包含一个JFXPanel保留在内存中,这是我从未使用过的,因为我在某处读到,否则JavaFX-Application-Thread已停止。 The problem now is that when the user reloads the page the run-method won't get executed and I don't get any error message or exception. 现在的问题是,当用户重新加载页面时,运行方法将不会执行,并且我也不会收到任何错误消息或异常。

I wrote an own class implementing runnable with a custom constructor. 我编写了一个自己的类,该类使用自定义构造函数来实现可运行。 The constructor is called and runs till the end but the run-Method wont get started. 构造函数将被调用并运行到最后,但run-Method不会启动。 I also tried do all work within the AccessController, but this also didn't work. 我也尝试在AccessController内完成所有工作,但是这也没有工作。

I really don't no how to solve this problem and appreciate any help. 我真的不是没有办法解决这个问题并感谢您的帮助。 Thanks in advance. 提前致谢。

Update 更新

I tried some more things: 我尝试了更多的事情:

  1. I examinated the running threads. 我检查了正在运行的线程。 When I start the Applet-GUI there is a JavaFX Application Thread and a QuantumRenderer thread. 当我启动Applet-GUI时,有一个JavaFX Application线程和一个QuantumRenderer线程。 When I reload the webpage, the threads won't show up again. 当我重新加载网页时,线程将不会再次显示。 Whenn reloading the Webpage befor I opened the GUI (and create the threads) everything works fine, but afert a second reload it fails. 在重新加载网页之前,我打开了GUI(并创建线程),但一切正常,但是第二次重新加载失败。

  2. I tried using Platform.setImplicitExit(false) . 我尝试使用Platform.setImplicitExit(false) With this option I don't need my background-object any more. 使用此选项,我不再需要背景对象。 When reloading the webpage I get a QuantumRenderer-0 uncaught: java.lang.IllegalMonitorStateException and the Java Console closes. 重新加载网页时,我未捕获QuantumRenderer-0:java.lang.IllegalMonitorStateException ,并且Java控制台关闭。 When starting the Applet everything works fine on my computer, but I don't want to crash Java and this approach didn't work on a different pc with same Java-version (8). 启动Applet时,在我的计算机上一切正常,但我不想使Java崩溃,并且这种方法在具有相同Java版本的另一台PC上也不起作用(8)。

Maybe this informations are helpfull. 也许这些信息是有帮助的。

Not sure if you solved this, but maybe this http://news.kynosarges.org/2014/05/01/simulating-platform-runandwait/ can help you 不知道您是否解决了这个问题,但是也许http://news.kynosarges.org/2014/05/01/simulating-platform-runandwait/可以为您提供帮助

runLater swallows any exceptions that the executed action might throw, as it's not designed to communicate anything back to the caller. runLater吞下了已执行操作可能引发的任何异常,因为它并非旨在将任何内容传达回调用方。 If you want error handling you need to specialize runAndWait for a Runnable subclass that provides such communication 如果要进行错误处理,则需要专门针对提供此类通信的Runnable子类运行runAndWait。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM