This is the correct answer. Please see the javadoc for more details.

best regards,

On 5/31/2014 10:19 PM, Jeff Martin wrote:
You might try calling that new JFXPanel() in your application main. Maybe go 
ahead and call Platform.setImplicitExit(false) as well.


On May 31, 2014, at 9:46 AM, Robert Krüger <> wrote:

That was quicker than I had hoped. Invoking close() on the stage
constructed in this way results in this here:

[ERROR|16:24:23] d.l.m.MediaTool Uncaught exception in thread JavaFX
Application Thread: [JavaFX Application Thread]
java.lang.IllegalStateException: This operation is permitted on the
event thread only; currentThread = JavaFX Application Thread
at ~[jfxrt.jar:na]

I checked in the debugger and
is null. This makes me believe the environment is not properly
initialized despite the invocation on new JFXPanel() that I have in
the EDT before the stage is built.

On Sat, May 31, 2014 at 4:15 PM, Robert Krüger <> wrote:
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 <> 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 <> wrote:


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?



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

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

Reply via email to