void () { UIUtil.invokeAndWaitIfNeeded(() -> { LaterInvocator.enterModal(myWindow1); ApplicationManager.getApplication().invokeLater(ENTER_MODAL, ModalityState.nonModal()); ApplicationManager.getApplication().invokeLater(new MyRunnable("1"), ModalityState.nonModal()); LaterInvocator.leaveModal(myWindow1); flushSwingQueue(); flushSwingQueue(); checkOrder(0); SwingUtilities.invokeLater(LEAVE_MODAL); flushSwingQueue(); flushSwingQueue(); checkOrder(1); }); }