Integrating JFX Dialog/Stage in Swing application

Robert Krüger krueger at
Sat May 31 14:15:51 UTC 2014

Hi Jeff,

thanks, yeah, that's a workaround I have also found. I am just asking
myself (and the JFX developers on this list) why this kind of
Integration is not supported directly.

Good to know that you have used this quite a bit. So I'll try using it
until someone brings up a nicer solution or I run into any problems



On Sat, May 31, 2014 at 3:57 PM, Jeff Martin <jeff at> wrote:
> I'm sure this isn't the proper answer, but I have used this call to initialize the FX toolkit on demand from various Swing contexts and it has always worked for me:
>         new javafx.embed.swing.JFXPanel();
> Then you would need the Platform.runLater(). Usually for the whole method that creates your UI and shows the Stage. In some cases, I would make the first line of my method that ends up invoking the JFX dialog something like this:
> public void doSomething()
> {
>         // Ensure we're on FX thread
>         if(!Platform.isFXApplicationThread()) {
>                 Platform.runLater(new Runnable() { public void run() { doSomething(); } return; }
>         … <create FX UI and do> ...
> }
> I've done quite a bit of this and it works without problems (for me).
> jeff martin
> On May 31, 2014, at 7:27 AM, Robert Krüger <krueger at> wrote:
>> Hi,
>> 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(
>> ~[jfxrt.jar:na]
>> at com.sun.javafx.application.PlatformImpl.runLater(
>> ~[jfxrt.jar:na]
>> at javafx.application.Platform.runLater( ~[jfxrt.jar:na]
>> at$1.actionPerformed(
>> ~[
>> 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
>> constructed.
>> 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
>> Platform.ensureInitialized().
>> Am I missing something obvious?
>> Thanks,
>> Robert

Robert Krüger
Managing Partner
Lesspain GmbH & Co. KG

More information about the openjfx-dev mailing list