void () { UIUtil.invokeAndWaitIfNeeded(() -> { LaterInvocator.enterModal(myWindow1); synchronized (this) { blockSwingThread(); SwingUtilities.invokeLater(new MyRunnable("1")); ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().invokeLater(new MyRunnable("3"), ModalityState.nonModal()), ModalityState.nonModal()); SwingUtilities.invokeLater(LEAVE_MODAL); ApplicationManager.getApplication().invokeLater(new MyRunnable("2"), ModalityState.nonModal()); } flushSwingQueue(); checkOrder(3); }); }