Here you can find the source of invokeLaterIfNeeded(Runnable runnable)
public static void invokeLaterIfNeeded(Runnable runnable)
//package com.java2s; /***/*from ww w .j a v a 2s.c om*/ * Copyright (C) 2010 Johan Henriksson * This code is under the Endrov / BSD license. See www.endrov.net * for the full text and how to cite. */ import javax.swing.*; public class Main { /** * Run operation in the swing thread. If the code is already executing in the swing thread, then it will not try * to switch. This would otherwise cause an exception */ public static void invokeLaterIfNeeded(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) runnable.run(); else { SwingUtilities.invokeLater(runnable); } } }