You can do so by using Platform.enterNestedEventLoop
to pause the execution of the event handler and Platform.exitNestedEventLoop
(available since JavaFX 9) to resume the execution:
private final Object PAUSE_KEY = new Object();
private void pause() {
Platform.enterNestedEventLoop(PAUSE_KEY);
}
private void resume() {
Platform.exitNestedEventLoop(PAUSE_KEY, null);
}
Platform.enterNestedEventLoop
returns when Platform.exitNestedEventLoop
is called with the same parameter passed as first argument.