I want to integrate openjfx into my Java 11 code. Using IntelliJ IDEA 2018.2.6 on Windows 10, I created a test project and tried out below code
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.TabPane;
public class Java11FXTestApplication {
public static void main(String[] args) {
JFXPanel dummyPanel;
TabPane dummyTabPane;
Scene dummyScene;
System.out.println("Creating JFX Panel");
dummyPanel = new JFXPanel();
System.out.println("Creating TabPane");
dummyTabPane = new TabPane();
System.out.println("Creating Scene");
dummyScene = new Scene(dummyTabPane);
System.out.println("Setting Scene");
dummyPanel.setScene(dummyScene); //Freezing here
System.out.println("Scene Created");
}
}
this code is freezing in setScene() method call. I tried debugging it and found that it the code wait indefinitely in secondaryLoop.enter() call in JFXPanel.setScene method. any Idea why?
This code works fine in JDK-8 but not working with java-11.0.1.
I am getting nowhere with this issue, kind of stuck at the Java11 JavaFX problem. Is there something wrong with the code? or any reported issue with javafx for java11
You're setting the
Scene
on the main thread. From the documentation ofJFXPanel
(emphasis mine):Wrap
setScene
in aPlatform.runLater
call (orSwingUtilities.invokeLater
).Note that, with your current code, once
main
returns the JVM will continue to run. Creating aJFXPanel
initializes the JavaFX runtime which won't exit until that last window is closed (only whenPlatform.isImplicitExit
istrue
) orPlatform.exit
is called. Since your code does neither, the JavaFX runtime will keep running.The documentation of
JFXPanel
also gives an example of how it expects to be used (note nearly everything happens on either the Event Dispatch Thread or JavaFX Application Thread):