Here you can find the source of invokeAndWaitAsNeeded(Runnable r)
Parameter | Description |
---|---|
r | The runnable to execute on the dispatch thread. |
public static void invokeAndWaitAsNeeded(Runnable r)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.lang.reflect.InvocationTargetException; public class Main { /**// www. ja v a 2 s. com * Invokes the given runnable on the Swing UI dispatch thread, blocking until the runnable has completed. If the * current thread is the dispatch thread, the runnable is simply executed. If the current thread is not the dispatch * thread, then the current thread is blocked until the dispatch thread has completed executing the runnable. * * @param r The runnable to execute on the dispatch thread. */ public static void invokeAndWaitAsNeeded(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InterruptedException | InvocationTargetException e) { e.printStackTrace(); Thread.currentThread().interrupt(); } } } }