Integrating JFX Dialog/Stage in Swing application

Robert Krüger krueger at
Sat May 31 12:27:34 UTC 2014


I am trying something which I thought would technically be the easiest
way of migrating parts of an existing application from Swing to JFX,
i.e. have a Swing JMenuItem trigger the showing of a JFX stage because
I thought this would technically even be cleaner than to have a swing
dialog containing an JFXPanel.

Doing this results in the following Exception:

java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(
at com.sun.javafx.application.PlatformImpl.runLater(
at javafx.application.Platform.runLater( ~[jfxrt.jar:na]

javadoc of runLater states:

This method must not be called before the FX runtime has been
initialized. For standard JavaFX applications that extend Application,
and use either the Java launcher or one of the launch methods in the
Application class to launch the application, the FX runtime is
initialized by the launcher before the Application class is loaded.
For Swing applications that use JFXPanel to display FX content, the FX
runtime is initialized when the first JFXPanel instance is

So this is consistent. Still I am wondering, why it should not be
supported to just trigger opening a stage from a Swing menu? Either by
Platform.runLater autoinitializing or offering a separate method like

Am I missing something obvious?



More information about the openjfx-dev mailing list