Quantcast

JavaFX and Swing on same Thread

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JavaFX and Swing on same Thread

Lusito
On the book "JavaFX- Rich Client Programming on the NetBeans Platform", the authors mentioned the experimental feature to run javafx on the same thread as swing.

I was wondering if anyone got this working.
I tried enabling it with this option in the app.conf:

Code:
 -J-Djavafx.embed.singleThread=true


But I get an exception on startup:


> at org.netbeans.core.windows.WindowManagerImpl.warnIfNotInEDT(WindowManagerImpl.java:1770)
> at org.netbeans.core.windows.ModeImpl.setBounds(ModeImpl.java:180)
> at org.netbeans.core.windows.PersistenceHandler.initModeFromConfig(PersistenceHandler.java:465)
> at org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:204)
> at org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:81)
> at org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:229)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
> at java.awt.EventQueue.access$500(EventQueue.java:97)
> at java.awt.EventQueue$3.run(EventQueue.java:709)
> at java.awt.EventQueue$3.run(EventQueue.java:703)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
> at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
> SEVERE [global]
> java.lang.AssertionError: Window System API is required to be called from AWT thread only, see http://core.netbeans.org/proposals/threading/
> at org.netbeans.core.windows.WindowManagerImpl.assertEventDispatchThread(WindowManagerImpl.java:1734)
> at org.netbeans.core.windows.ModeImpl.getSelectedTopComponent(ModeImpl.java:312)
> at org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:236)
> at org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:81)
> at org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:229)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
> at java.awt.EventQueue.access$500(EventQueue.java:97)
> at java.awt.EventQueue$3.run(EventQueue.java:709)
> at java.awt.EventQueue$3.run(EventQueue.java:703)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
> at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
> [catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
>


Looking at the code, it seems SwingUtilities.isEventDispatchThread() is returning false at that point. That's weird, since the stacktrace shows it is on the EDT.

I know this is marked experimental, but why mention it in the book, if it's preventing a netbeans platform app from running? So I'm guessing there must be some way to get this running.




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JavaFX and Swing on same Thread

Emilian Bold-2
I haven't used this, but how can SwingUtilities.isEventDispatchThread() return false and still be on the EDT?

You can probably make a small self-contained app and verify if this truly works.

Another possibility is that org.netbeans.core.TimableEventQueue is getting in the way of JavaFX.


--emi

On Fri, Mar 3, 2017 at 9:08 PM, Lusito <[hidden email]> wrote:
On the book "JavaFX- Rich Client Programming on the NetBeans Platform", the authors mentioned the experimental feature to run javafx on the same thread as swing.

I was wondering if anyone got this working.
I tried enabling it with this option in the app.conf:

Code:
 -J-Djavafx.embed.singleThread=true


But I get an exception on startup:


>       at org.netbeans.core.windows.WindowManagerImpl.warnIfNotInEDT(WindowManagerImpl.java:1770)
>       at org.netbeans.core.windows.ModeImpl.setBounds(ModeImpl.java:180)
>       at org.netbeans.core.windows.PersistenceHandler.initModeFromConfig(PersistenceHandler.java:465)
>       at org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:204)
>       at org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:81)
>       at org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:229)
>       at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
>       at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
>       at java.awt.EventQueue.access$500(EventQueue.java:97)
>       at java.awt.EventQueue$3.run(EventQueue.java:709)
>       at java.awt.EventQueue$3.run(EventQueue.java:703)
>       at java.security.AccessController.doPrivileged(Native Method)
>       at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
>       at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
>       at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
>       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
>       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
>       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
>       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
>       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
>       at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
> SEVERE [global]
> java.lang.AssertionError: Window System API is required to be called from AWT thread only, see http://core.netbeans.org/proposals/threading/
>       at org.netbeans.core.windows.WindowManagerImpl.assertEventDispatchThread(WindowManagerImpl.java:1734)
>       at org.netbeans.core.windows.ModeImpl.getSelectedTopComponent(ModeImpl.java:312)
>       at org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:236)
>       at org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:81)
>       at org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:229)
>       at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
>       at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
>       at java.awt.EventQueue.access$500(EventQueue.java:97)
>       at java.awt.EventQueue$3.run(EventQueue.java:709)
>       at java.awt.EventQueue$3.run(EventQueue.java:703)
>       at java.security.AccessController.doPrivileged(Native Method)
>       at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
>       at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
>       at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
> [catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
>       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
>       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
>       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
>       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
>       at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
>


Looking at the code, it seems SwingUtilities.isEventDispatchThread() is returning false at that point. That's weird, since the stacktrace shows it is on the EDT.

I know this is marked experimental, but why mention it in the book, if it's preventing a netbeans platform app from running? So I'm guessing there must be some way to get this running.





Loading...