Java Swing UI Thread Event dispatchOnAWTThreadNow(Runnable r)

Here you can find the source of dispatchOnAWTThreadNow(Runnable r)

Description

dispatch On AWT Thread Now

License

Open Source License

Declaration

public static void dispatchOnAWTThreadNow(Runnable r) 

Method Source Code

//package com.java2s;
/*------------------------------------------------------------------
 * Copyright (c) 2014 Cisco Systems/*from w  w  w .  j  a  va  2 s .c  o  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *------------------------------------------------------------------*/

import java.lang.reflect.InvocationTargetException;

import javax.swing.SwingUtilities;

public class Main {
    public static void dispatchOnAWTThreadNow(Runnable r) {
        if (SwingUtilities.isEventDispatchThread())
            r.run();
        else
            try {
                SwingUtilities.invokeAndWait(r);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}

Related

  1. assertIsEDT()
  2. assertNotEventDispatchThread()
  3. callOnGUIThread(Runnable runnable)
  4. checkForEventDispatchThread()
  5. dispatchOnAWTThreadLater(Runnable r)
  6. dispatchToEDT(Runnable runnable)
  7. doInBackground(final Runnable r)
  8. doInBackground(final Runnable runnable)
  9. doLater(final long milliseconds, final Runnable doThis)