void () { if (!SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("Must call from EDT"); Semaphore semaphore = new Semaphore(); semaphore.down(); invokeLater(ModalityState.any(), Conditions.alwaysFalse(), semaphore::up); while (!semaphore.isUp()) { EDT.dispatchAllInvocationEvents(); } }