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 com.sun.glass.ui.Application.checkEventThread(Application.java:427)
~[jfxrt.jar:na]
at com.sun.glass.ui.View.isClosed(View.java:409) ~[jfxrt.jar:na]
at 
com.sun.glass.ui.mac.MacTouchInputSupport.notifyNextTouchEvent(MacTouchInputSupport.java:122)
~[jfxrt.jar:na]
at 
com.sun.glass.ui.mac.MacGestureSupport.notifyNextTouchEvent(MacGestureSupport.java:77)
~[jfxrt.jar:na]

I checked in the debugger and com.sun.glass.ui.Application#eventThread
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 <krue...@lesspain.de> 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
> :-).
>
> Cheers,
>
> Robert
>
> On Sat, May 31, 2014 at 3:57 PM, Jeff Martin <j...@reportmill.com> 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 stage.show()> ...
>> }
>>
>> 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 <krue...@lesspain.de> 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(PlatformImpl.java:276)
>>> ~[jfxrt.jar:na]
>>> at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:271)
>>> ~[jfxrt.jar:na]
>>> at javafx.application.Platform.runLater(Platform.java:78) ~[jfxrt.jar:na]
>>> at 
>>> de.lesspain.mediatool.menu.ToolsSubmenu$1.actionPerformed(ToolsSubmenu.java:20)
>>> ~[
>>>
>>> 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
>
> www.lesspain-software.com



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

www.lesspain-software.com

Reply via email to