JavaFx 2.x - Swing : Not on FX application thread

前端 未结 1 761
清歌不尽
清歌不尽 2020-12-05 11:12

I am trying to use JavaFx 2.x and Swing application by using a JInternalFrame in which attach a JFXPanel

My code below

public class InternalFrameWith         


        
相关标签:
1条回答
  • 2020-12-05 11:55

    See the 'JavaFX in Swing' tutorial. You are performing JavaFX operations which should run on the JavaFX thread on the Swing thread (Event Dispatch Thread).

    Luckily they learnt from their previous mistakes and now throw exceptions when you perform operations on the wrong thread. That is the exception you encountered.

    Use the Platform#runLater as shown in that tutorial

    Platform.runLater(new Runnable() {
            @Override
            public void run() {
              //javaFX operations should go here
            }
       });
    

    The construction of the JFXPanel can remain on the EDT (which is also illustrated in that tutorial)

    0 讨论(0)
提交回复
热议问题