Java Swing UI Thread Event invokeAfter(final Runnable execute, int after)

Here you can find the source of invokeAfter(final Runnable execute, int after)

Description

Runs the supplied class after a certain period of time, the thread will be executed in the EDT.

License

Apache License

Parameter

Parameter Description
execute The runnable object whose method will be called after the specified delay
after The delay in ms before the event will be called

Declaration

public static void invokeAfter(final Runnable execute, int after) 

Method Source Code

//package com.java2s;
/*/*from  ww w.ja  va2s .c o  m*/
 * SwingBugUtilities.java
 *
 * Created on March 30, 2007, 12:27 AM
 *
 * Copyright 2006-2007 Nigel Hughes
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at http://www.apache.org/
 * licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public class Main {
    /** 
     * Runs the supplied class after a certain period of time, the thread
     * will be executed in the EDT. 
     *
     * @param execute The runnable object whose method will be called after the
     * specified delay
     * @param after The delay in ms before the event will be called
     */
    public static void invokeAfter(final Runnable execute, int after) {
        Timer timer = new Timer(after, new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                execute.run();
            }
        });

        timer.setRepeats(false);
        timer.start();
    }
}

Related

  1. executeTask(final Runnable task, final boolean async)
  2. getInstalledThemes(LookAndFeel laf)
  3. invoke(Runnable r)
  4. invoke(Runnable runnable)
  5. invoke(Runnable runnable)
  6. invokeAndContiune(Runnable runnable)
  7. invokeAndWait(final Runnable r)
  8. invokeAndWait(Runnable task)
  9. invokeAndWaitAsNeeded(Runnable r)