run On Swing Thread - Java Swing

Java examples for Swing:Swing Thread

Description

run On Swing Thread

Demo Code


//package com.java2s;

public class Main {
    public static void runOnSwingThread(Runnable run) {
        if (javax.swing.SwingUtilities.isEventDispatchThread()) {
            run.run();/* w  w w  .  ja v  a 2s  .  com*/
        } else {
            runOnSwingThreadLater(run);
        }
    }

    public static void runOnSwingThreadLater(Runnable run) {
        javax.swing.SwingUtilities.invokeLater(run);
    }
}

Related Tutorials