run And Wait on JavaFX Thread - Java JavaFX

Java examples for JavaFX:JavaFX Thread

Description

run And Wait on JavaFX Thread

Demo Code


//package com.java2s;
import java.util.concurrent.FutureTask;
import javafx.application.Platform;

public class Main {
    public static void runAndWait(Runnable runnable) {
        try {/* ww  w . j a v a  2s .  c  o m*/
            if (Platform.isFxApplicationThread()) {
                runnable.run();
            } else {
                FutureTask<Object> futureTask = new FutureTask<>(runnable,
                        null);
                Platform.runLater(futureTask);
                futureTask.get();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials