Java Utililty Methods Swing UI Thread Event

List of utility methods to do Swing UI Thread Event

Description

The list of methods to do Swing UI Thread Event are organized into topic(s).

Method

TresultOfOnEventThread(final Callable task)
Execute a task on the event dispatch thread and return the result.
if (SwingUtilities.isEventDispatchThread()) {
    try {
        return task.call();
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException(e.getClass().getSimpleName() + " thrown by task", e);
...
voidrunAndWaitOnEDT(Runnable r)
run And Wait On EDT
if (EventQueue.isDispatchThread()) {
    r.run();
} else {
    try {
        SwingUtilities.invokeAndWait(r);
    } catch (InvocationTargetException e) {
        e.printStackTrace(); 
voidrunAndWaitOnEDT(Runnable runnable)
Run on EDT if not already on EDT.
try {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        SwingUtilities.invokeAndWait(runnable);
} catch (Throwable e) {
    throw new RuntimeException(e);
...
voidrunInDispatchThread(Runnable r)
run In Dispatch Thread
if (!SwingUtilities.isEventDispatchThread()) {
    try {
        SwingUtilities.invokeAndWait(r);
    } catch (Exception e) {
        throw new RuntimeException(e);
} else {
    r.run();
...
voidrunInEDT(final Runnable runnable)
run In EDT
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeLater(runnable);
TrunInEDT(final Supplier supplier)
Runs arbitrary code in the Event Dispatch Thread.
return runInEDT(supplier, null);
voidrunInEdt(Runnable r)
run In Edt
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    SwingUtilities.invokeLater(r);
voidrunInEDTAndWait(Runnable task)
run In EDT And Wait
if (SwingUtilities.isEventDispatchThread()) {
    task.run();
} else {
    try {
        SwingUtilities.invokeAndWait(task);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
...
voidrunInEventDispatchThread(final Runnable r)
run In Event Dispatch Thread
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    SwingUtilities.invokeLater(r);
voidrunInEventDispatchThread(Runnable r)
run In Event Dispatch Thread
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    SwingUtilities.invokeLater(r);