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

voidrunOnEDT(final Runnable r)
Runs the given runnable on the event dispatch thread.
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    SwingUtilities.invokeLater(r);
voidrunOnSwingThread(Runnable doRun)
Runs the given Runnable on the Swing event dispatch thread.
if (SwingUtilities.isEventDispatchThread()) {
    doRun.run();
} else {
    SwingUtilities.invokeLater(doRun);
voidrunOnSwingThread(Runnable run)
run On Swing Thread
if (javax.swing.SwingUtilities.isEventDispatchThread()) {
    run.run();
} else {
    runOnSwingThreadLater(run);
voidrunSafe(Runnable runnable)
run Safe
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    try {
        SwingUtilities.invokeAndWait(runnable);
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
        throw new Error(e);
...
voidrunTimer(int duration, final Runnable run)
run Timer
Timer t = new Timer(duration, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        run.run();
});
t.setRepeats(false);
t.start();
...
voidsafeGUIRun(Runnable runnable)
safe GUI Run
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeLater(runnable);
voidsafelyRunBlockingRoutine(Runnable runnable)
safely Run Blocking Routine
if (SwingUtilities.isEventDispatchThread()) {
    new Thread(runnable).start();
} else {
    runnable.run();
voidsafeSwingCall(@Nonnull final Runnable runnable)
safe Swing Call
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeLater(runnable);
voidsaveInvokeAndWait(Runnable run)
save Invoke And Wait
if (SwingUtilities.isEventDispatchThread())
    run.run();
else {
    try {
        SwingUtilities.invokeAndWait(run);
    } catch (Exception _e) {
        throw new RuntimeException(_e);
voidthrowIfNotOnEDT()
throw If Not On EDT
if (!SwingUtilities.isEventDispatchThread()) {
    throw new RuntimeException();