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