Java Swing UI Thread Event doLater(final long milliseconds, final Runnable doThis)

Here you can find the source of doLater(final long milliseconds, final Runnable doThis)

Description

Schedule something to occur at some specified point in the future in the Swing Event thread.

License

Academic Free License

Declaration

public static Thread doLater(final long milliseconds, final Runnable doThis) 

Method Source Code

//package com.java2s;
/*//www .  ja  va2 s .c  o m
  Copyright 2006 by Sean Luke and George Mason University
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

import javax.swing.*;

public class Main {
    /** Schedule something to occur at some specified point in the future in the Swing Event thread. */
    public static Thread doLater(final long milliseconds, final Runnable doThis) {
        Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(milliseconds);
                    SwingUtilities.invokeAndWait(doThis);
                } catch (InterruptedException e) {
                    /* shouldn't happen -- we could do an invokeAndWait in case tho */ } catch (java.lang.reflect.InvocationTargetException e) {
                    /* shouldn't happen */ }
            }
        });
        thread.start();
        return thread;
    }
}

Related

  1. dispatchOnAWTThreadLater(Runnable r)
  2. dispatchOnAWTThreadNow(Runnable r)
  3. dispatchToEDT(Runnable runnable)
  4. doInBackground(final Runnable r)
  5. doInBackground(final Runnable runnable)
  6. doLaterOnEventThread(Runnable task)
  7. doOnEventThreadAndWait(Runnable task)
  8. doSwing(Runnable r)
  9. edtExecutor()