Java Swing UI Thread Event toEDT(Runnable r, boolean wait)

Here you can find the source of toEDT(Runnable r, boolean wait)

Description

to EDT

License

Apache License

Declaration

public static void toEDT(Runnable r, boolean wait) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;
import java.lang.reflect.InvocationTargetException;

public class Main {
    public static void toEDT(Runnable r, boolean wait) {
        if (wait)
            waitOnEDT(r);/*from   w  w  w. ja va2  s  .co  m*/
        else
            toEDT(r);
    }

    public static void toEDT(Runnable r) {
        if (SwingUtilities.isEventDispatchThread()) {
            //new Thread(r).start();
            r.run();
        } else {
            SwingUtilities.invokeLater(r);
        }
    }

    public static void waitOnEDT(Runnable r) {
        if (SwingUtilities.isEventDispatchThread()) {
            r.run();
        } else {
            try {
                SwingUtilities.invokeAndWait(r);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. safeGUIRun(Runnable runnable)
  2. safelyRunBlockingRoutine(Runnable runnable)
  3. safeSwingCall(@Nonnull final Runnable runnable)
  4. saveInvokeAndWait(Runnable run)
  5. throwIfNotOnEDT()
  6. waitOnEDT(Runnable r)