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

voidrunInEventDispatchThread(Runnable runnable)
Ensure that the specified ruannable task will run only in the event dispatch thread.
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeLater(runnable);
voidrunInEventDispatchThread(Runnable runnable)
run In Event Dispatch Thread
try {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException | InvocationTargetException e) {
    throw new RuntimeException(e);
...
voidrunInEventDispatchThreadAndWait(final Runnable r)
run In Event Dispatch Thread And Wait
if (SwingUtilities.isEventDispatchThread()) {
    r.run();
} else {
    try {
        SwingUtilities.invokeAndWait(r);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
...
voidrunInSwingThread(final Runnable runnable)
run In Swing Thread
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    try {
        SwingUtilities.invokeAndWait(runnable);
    } catch (final InvocationTargetException | InterruptedException e) {
        throw new RuntimeException(e);
voidrunInSwingThread(Runnable runnable)
run In Swing Thread
try {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        runLater(runnable);
} catch (Exception e) {
    throw new RuntimeException(e);
...
voidrunLater(Runnable runnable)
run Later
SwingUtilities.invokeLater(runnable);
voidrunLaterAndWait(final Runnable runnable)
Run the given runnable in the EDT and wait until its finished.
final CountDownLatch l_latch = new CountDownLatch(1);
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        runnable.run();
        l_latch.countDown();
});
while (true) {
...
voidrunModalProcess(String title, final Runnable runnable)
run Modal Process
final JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
final JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
contentPane.setLayout(new BorderLayout());
contentPane.add(new JLabel(title), BorderLayout.NORTH);
contentPane.add(progressBar, BorderLayout.CENTER);
voidrunNowInEdt(Runnable runnable)
run Now In Edt
if (SwingUtilities.isEventDispatchThread()) {
    runnable.run();
} else {
    SwingUtilities.invokeAndWait(runnable);
voidrunOnDispatchThread(Runnable runnable)
run On Dispatch Thread
if (EventQueue.isDispatchThread()) {
    runnable.run();
} else {
    try {
        SwingUtilities.invokeAndWait(runnable);
    } catch (InvocationTargetException e) {
        Throwable t = e.getCause();
        if (t instanceof Error)
...