Java Swing UI Thread Event runOnDispatchThread(Runnable runnable)

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

Description

run On Dispatch Thread

License

Apache License

Declaration

public static void runOnDispatchThread(Runnable runnable) 

Method Source Code


//package com.java2s;
// This file is provided to you under the terms of the Apache License, Version 2.0.

import java.awt.*;
import java.lang.reflect.InvocationTargetException;

import javax.swing.SwingUtilities;

public class Main {
    public static void runOnDispatchThread(Runnable runnable) {
        if (EventQueue.isDispatchThread()) {
            runnable.run();// w  w  w  .j  a v a  2 s  . co m
        } else {
            try {
                SwingUtilities.invokeAndWait(runnable);
            } catch (InvocationTargetException e) {
                Throwable t = e.getCause();
                if (t instanceof Error)
                    throw (Error) t.getCause();
                if (t instanceof RuntimeException)
                    throw (RuntimeException) t.getCause();
                throw new IllegalStateException("Unchecked exception thrown unexpectedly", t);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

Related

  1. runInSwingThread(Runnable runnable)
  2. runLater(Runnable runnable)
  3. runLaterAndWait(final Runnable runnable)
  4. runModalProcess(String title, final Runnable runnable)
  5. runNowInEdt(Runnable runnable)
  6. runOnEDT(final Runnable r)
  7. runOnSwingThread(Runnable doRun)
  8. runOnSwingThread(Runnable run)
  9. runSafe(Runnable runnable)