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
Sceneon the main thread. From the documentation ofJFXPanel(emphasis mine):Wrap
setScenein aPlatform.runLatercall (orSwingUtilities.invokeLater).Note that, with your current code, once
mainreturns the JVM will continue to run. Creating aJFXPanelinitializes the JavaFX runtime which won't exit until that last window is closed (only whenPlatform.isImplicitExitistrue) orPlatform.exitis called. Since your code does neither, the JavaFX runtime will keep running.The documentation of
JFXPanelalso gives an example of how it expects to be used (note nearly everything happens on either the Event Dispatch Thread or JavaFX Application Thread):