List of usage examples for javafx.application Platform runLater
public static void runLater(Runnable runnable)
From source file:Main.java
public static void runActionLater(Runnable runnable) { Platform.runLater(runnable); }
From source file:Main.java
public static void runOnUiThread(Runnable run) { if (isUiThread()) { run.run();/*from w ww.ja va 2s . co m*/ } else { Platform.runLater(run); } }
From source file:Main.java
public static void executeInFXThread(Runnable runnable) { if (Platform.isFxApplicationThread()) { runnable.run();/*from w ww . j av a 2 s .c o m*/ } else { Platform.runLater(runnable); } }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void runAndWait(Runnable runnable) throws InterruptedException, ExecutionException { FutureTask<?> future = new FutureTask(runnable, null); Platform.runLater(future); future.get();/*from w w w . java2 s . c om*/ }
From source file:Main.java
private static void initAndShowGUI() { final JFrame frame = new JFrame("JavaFX / Swing Integrated"); final JFXPanel fxPanel = new JFXPanel(); frame.add(fxPanel);/*from w ww . j a v a 2 s .c o m*/ frame.setVisible(true); Platform.runLater(new Runnable() { @Override public void run() { initFX(fxPanel); } }); }
From source file:Main.java
public static void runAndWait(Runnable action) { if (action == null) throw new NullPointerException("action"); // run synchronously on JavaFX thread if (Platform.isFxApplicationThread()) { action.run();/*w ww . ja v a 2s . com*/ return; } // queue on JavaFX thread and wait for completion final CountDownLatch doneLatch = new CountDownLatch(1); Platform.runLater(() -> { try { action.run(); } finally { doneLatch.countDown(); } }); try { doneLatch.await(); } catch (InterruptedException e) { // ignore exception } }
From source file:Main.java
public static void runActionLater(final Runnable runnable) { if (Platform.isFxApplicationThread()) { runnable.run();// w ww . j av a2 s.com } else { try { uiSemaphore.acquire(); Platform.runLater(() -> { try { runnable.run(); releaseUiSemaphor(); } catch (Exception e) { releaseUiSemaphor(); throw new RuntimeException(e); } }); } catch (Exception e) { releaseUiSemaphor(); throw new RuntimeException(e); } } }
From source file:Main.java
public static <T> T runAndWait(Callable<T> callable) throws InterruptedException, ExecutionException { FutureTask<T> future = new FutureTask<T>(callable); Platform.runLater(future); return future.get(); }
From source file:Main.java
/** * If called from the FX Application Thread * invokes a runnable directly blocking the calling code * Otherwise//from ww w. j a v a 2 s .com * uses Platform.runLater without blocking */ static void runOnFxThread(Runnable runnable) { if (Platform.isFxApplicationThread()) { runnable.run(); } else { Platform.runLater(runnable); } }
From source file:Main.java
/** * Creates a popup containing error without any pretty things for a graphical way to show errors * @param error Error string to show//from w ww.ja va 2s . c o m */ public static void showError(String error) { if (Platform.isFxApplicationThread()) { Stage s = new Stage(); VBox v = new VBox(); v.getChildren().add(new Label("Error [" + error + ']')); Scene sc = new Scene(v); s.setTitle("Fail"); s.setScene(sc); s.show(); } else { Platform.runLater(() -> { Stage s = new Stage(); VBox v = new VBox(); v.getChildren().add(new Label("Error [" + error + ']')); Scene sc = new Scene(v); s.setTitle("Fail"); s.setScene(sc); s.show(); }); } }