Skip to content

Instantly share code, notes, and snippets.

@grignaak
Created July 14, 2011 21:06
Show Gist options
  • Save grignaak/1083442 to your computer and use it in GitHub Desktop.
Save grignaak/1083442 to your computer and use it in GitHub Desktop.
Swing EDT utilities
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;
public class EventQueue {
private EventQueue() {}
public static void invokeAndWait(Runnable doRun) {
try {
SwingUtilities.invokeAndWait(doRun);
} catch (Exception e) {
throw Exceptions.rethrow(e);
}
}
public static void invokeLater(Runnable doRun) {
SwingUtilities.invokeLater(doRun);
}
public static boolean isEventDispatchThread() {
return SwingUtilities.isEventDispatchThread();
}
public static <T> T invokeAndGet(final Callable<T> doRun) {
final AtomicReference<T> result = new AtomicReference<T>();
invokeAndWait(new Runnable() {
public void run() {
try {
result.set(doRun.call());
} catch (Exception e) {
Exceptions.rethrow(e);
}
}
});
return result.get();
}
}
@grignaak
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment