Search code examples
javarunnable

What is the difference between SwingUtilities/Platform .runLater?


I have two seperate codes, one is:

    Platform.runLater(new Runnable() {
        public void run() {

        }
    });

The other one is

     SwingUtilities.invokeLater(new Runnable() {
        public void run() {
        }
    });

I want to know what the difference between the two are, and when to use one or the other or if they mean the exact same thing. Thanks for your help!


Solution

  • Platform is from the JavaFX framework, SwingUtilities (which delegates to EventQueue) is from the Swing framework.

    The difference is based around the differences between how the two frameworks handle event dispatching.

    Each would use a single thread to perform their event dispatching roles, this would suggest that JavaFX is using a different Thread from Swing.

    You should use Platform.runLater when dealing with JavaFX and SwingUtilities when dealing with Swing...

    Take a look at JavaFX Architecture, which might provide a little more insight, in particular Glass Windowing Toolkit