Here you can find the source of runInEventDispatchThread(Runnable runnable)
public static void runInEventDispatchThread(Runnable runnable)
//package com.java2s; /**//from ww w. j ava 2 s . c o m * JBackup is a software managing backups. * * Copyright (C) 2013-2014 Fabien DUMINY (fabien [dot] duminy [at] webmails [dot] com) * * JBackup is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * JBackup is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ import javax.swing.*; import java.lang.reflect.InvocationTargetException; public class Main { public static void runInEventDispatchThread(Runnable runnable) { try { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeAndWait(runnable); } } catch (InterruptedException | InvocationTargetException e) { throw new RuntimeException(e); } } }