Here you can find the source of invokeAndWaitSafely(final Runnable runnable)
Parameter | Description |
---|---|
runnable | runnable |
public static void invokeAndWaitSafely(final Runnable runnable)
//package com.java2s; /*/* w w w . j a va2 s .c om*/ * This file is part of WebLookAndFeel library. * * WebLookAndFeel library 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. * * WebLookAndFeel library 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 WebLookAndFeel library. If not, see <http://www.gnu.org/licenses/>. */ import javax.swing.*; import java.lang.reflect.InvocationTargetException; public class Main { /** * Will invoke the specified action in EDT in case it is called from non-EDT thread. * It will also block any exceptions thrown by "invokeAndWait" method. * * @param runnable runnable */ public static void invokeAndWaitSafely(final Runnable runnable) { try { invokeAndWait(runnable); } catch (final Throwable e) { // } } /** * Will invoke the specified action in EDT in case it is called from non-EDT thread. * * @param runnable runnable * @throws InterruptedException * @throws java.lang.reflect.InvocationTargetException */ public static void invokeAndWait(final Runnable runnable) throws InterruptedException, InvocationTargetException { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeAndWait(runnable); } } }