Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Platform.runLater() after site reload

I am writing an Java Applet using JavaFX embedded in Swing. Users are able to start a Swing-GUI with JavaFX components using JFXPanel with the following code:

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. 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. 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. I also tried do all work within the AccessController, but this also didn't work.

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. 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.

  2. I tried using 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. 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).

Maybe this informations are helpfull.

like image 425
Mese Avatar asked Nov 17 '25 20:11

Mese


1 Answers

Not sure if you solved this, but maybe this http://news.kynosarges.org/2014/05/01/simulating-platform-runandwait/ can help you

runLater swallows any exceptions that the executed action might throw, as it’s not designed to communicate anything back to the caller. If you want error handling you need to specialize runAndWait for a Runnable subclass that provides such communication

like image 141
Jorge Avatar answered Nov 20 '25 11:11

Jorge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!