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

voidexecuteTask(final Runnable task, final boolean async)
execute Task
if (async) {
    SwingUtilities.invokeLater(task);
} else {
    if (SwingUtilities.isEventDispatchThread()) {
        task.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(task);
...
ListgetInstalledThemes(LookAndFeel laf)
get Installed Themes
return Collections.EMPTY_LIST;
voidinvoke(Runnable r)
invoke
if (SwingUtilities.isEventDispatchThread())
    r.run();
else
    SwingUtilities.invokeLater(r);
voidinvoke(Runnable runnable)
invoke
dispatch(runnable);
voidinvoke(Runnable runnable)
invoke
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    try {
        SwingUtilities.invokeAndWait(runnable);
    } catch (InvocationTargetException | InterruptedException e) {
        throw new RuntimeException(e);
voidinvokeAfter(final Runnable execute, int after)
Runs the supplied class after a certain period of time, the thread will be executed in the EDT.
Timer timer = new Timer(after, new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
        execute.run();
});
timer.setRepeats(false);
timer.start();
voidinvokeAndContiune(Runnable runnable)
invoke And Contiune
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeLater(runnable);
voidinvokeAndWait(final Runnable r)
Runs r in the event dispatch thread, which may be the current thread.
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    SwingUtilities.invokeAndWait(r);
voidinvokeAndWait(Runnable task)
invoke And Wait
if (SwingUtilities.isEventDispatchThread()) {
    task.run();
} else {
    try {
        SwingUtilities.invokeAndWait(task);
    } catch (Exception ex) {
        ex.printStackTrace();
voidinvokeAndWaitAsNeeded(Runnable r)
Invokes the given runnable on the Swing UI dispatch thread, blocking until the runnable has completed.
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    try {
        SwingUtilities.invokeAndWait(r);
    } catch (InterruptedException | InvocationTargetException e) {
        e.printStackTrace();
        Thread.currentThread().interrupt();
...