Java Swing How to - Check thread name for Swing thread








Question

We would like to know how to check thread name for Swing thread.

Answer

import javax.swing.SwingUtilities;
//from  w w w  . ja  v a 2s . c o  m
public class Main {
  public static void main(String[] args) {
    try {
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          System.out.println("Hello World on " + Thread.currentThread());
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("Finished on " + Thread.currentThread());
  }
}