Java Swing UI Thread Event runInEventDispatchThread(Runnable runnable)

Here you can find the source of runInEventDispatchThread(Runnable runnable)

Description

run In Event Dispatch Thread

License

Open Source License

Declaration

public static void runInEventDispatchThread(Runnable runnable) 

Method Source Code

//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);
        }
    }
}

Related

  1. runInEDT(final Supplier supplier)
  2. runInEdt(Runnable r)
  3. runInEDTAndWait(Runnable task)
  4. runInEventDispatchThread(final Runnable r)
  5. runInEventDispatchThread(Runnable r)
  6. runInEventDispatchThread(Runnable runnable)
  7. runInEventDispatchThreadAndWait(final Runnable r)
  8. runInSwingThread(final Runnable runnable)
  9. runInSwingThread(Runnable runnable)