Createing ContextMenu outside of FX thread

Werner Lehmann lehmann at
Tue Apr 24 10:11:46 PDT 2012


I just noticed that I cannot create a ContextMenu in the Swing EDT. The 
following fails in the build method:

     ContextMenu cm = ContextMenuBuilder.create()
             new MenuItem("item"))

I was under the impression that adding to a scene graph must be done in 
the FX thread but I am not doing that here. Although the trace says 

> Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0
> 	at
> 	at
> 	at javafx.scene.Scene.<init>(
> 	at javafx.scene.Scene.<init>(
> 	at javafx.stage.PopupWindow.<init>(
> 	at javafx.scene.control.PopupControl.<init>(
> 	at javafx.scene.control.ContextMenu.<init>(
> 	at

So, I expected that setting the contextmenu on a button or something 
which was already part of a scene would require the FX thread context - 
but not building it. Is ContextMenu special because it is a PopupWindow 
and not a Node, or is this a misconception on my part?


More information about the openjfx-dev mailing list