Java tutorial
//package com.java2s; /* * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ import java.util.Set; import java.util.HashSet; import javafx.application.Platform; import com.sun.javafx.tk.Toolkit; public class Main { private static final Set<Object> eventLoopKeys = new HashSet<>(); static void leaveFXNestedLoop(Object nestedLoopKey) { if (!eventLoopKeys.contains(nestedLoopKey)) return; if (Platform.isFxApplicationThread()) { Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null); } else { Platform.runLater(() -> { Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null); }); } eventLoopKeys.remove(nestedLoopKey); } }