Example usage for javafx.application Platform runLater

List of usage examples for javafx.application Platform runLater

Introduction

In this page you can find the example usage for javafx.application Platform runLater.

Prototype

public static void runLater(Runnable runnable) 

Source Link

Document

Run the specified Runnable on the JavaFX Application Thread at some unspecified time in the future.

Usage

From source file:ch.unibas.fittingwizard.presentation.base.progress.ProgressPage.java

@Override
public void setTitle(final String title) {
    logger.info(title);// w ww.j a  va  2  s.  co  m
    Platform.runLater(new CatchedRunnable() {
        @Override
        public void safelyRun() {
            lblTitle.textProperty().setValue(title);
        }
    });
}

From source file:pts4.googlemaps.Weather.java

/**
 * @param args the command line arguments
 *//*ww  w.j  a  va  2s  . c  o  m*/
public Weather(double longitude, double latitude) throws IOException, JSONException {

    JSONObject json = WeerBerichtJSON.readJsonFromUrl(latitude, longitude);
    JSONObject jsoneind = (JSONObject) json.get("currently");
    temprature = ((jsoneind.getDouble("temperature") - 32) / 1.8);
    System.out.print(Math.round(temprature));
    summary = jsoneind.getString("summary");
    Platform.runLater(new Runnable() {

        @Override
        public void run() {

            MessageBox msg = new MessageBox((int) temprature + "dgrees and " + summary, MessageBoxType.OK_ONLY);
            msg.showAndWait();
        }
    });

}

From source file:org.phoenicis.javafx.UiMessageSenderJavaFXImplementation.java

@Override
public <R> R run(Supplier<R> function) {

    // runBackground synchronously on JavaFX thread
    if (Platform.isFxApplicationThread()) {
        return function.get();
    }//from  w  w w . j a v a 2s. c o m

    // queue on JavaFX thread and wait for completion
    final CountDownLatch doneLatch = new CountDownLatch(1);
    final MutableObject result = new MutableObject();
    Platform.runLater(() -> {
        try {
            result.setValue(function.get());
        } finally {
            doneLatch.countDown();
        }
    });

    try {
        doneLatch.await();
    } catch (InterruptedException e) {
        // ignore exception
    }

    return (R) result.getValue();
}

From source file:org.kordamp.javatrove.example04.util.ApplicationEventHandler.java

@Handler
public void handleThrowable(ThrowableEvent event) {
    Platform.runLater(() -> {
        TitledPane pane = new TitledPane();
        pane.setCollapsible(false);//  w  w  w. ja  v  a 2 s .  c om
        pane.setText("Stacktrace");
        TextArea textArea = new TextArea();
        textArea.setEditable(false);
        pane.setContent(textArea);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        event.getThrowable().printStackTrace(new PrintStream(baos));
        textArea.setText(baos.toString());

        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error");
        alert.setHeaderText("An unexpected error occurred");
        alert.getDialogPane().setContent(pane);
        alert.showAndWait();
    });
}

From source file:com.toyota.carservice.controller.SwitchController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    Platform.runLater(() -> {
        new FadeInTransition(btnInformasiService).play();
        new FadeInTransition(btnKelolaData).play();
        lblClose.setOnMouseClicked((MouseEvent event) -> {
            Platform.exit();// www  .  j av a 2s.c  o m
            System.exit(0);
        });
    });
}

From source file:testclientside.implement.implPerson.java

@Override
public ObservableList<Person> select() {
    ObservableList<Person> listData = FXCollections.observableArrayList();
    JSONArray arr;//from   w  w w.j a v a2  s . com
    String jsonStr = Service.ServiceGet("select.php");
    if (jsonStr != null) {
        layoutController.statusConnection = 1;
        try {
            JSONObject jsonObj = new JSONObject(jsonStr);
            arr = jsonObj.getJSONArray("hobi");
            for (int i = 0; i < arr.length(); i++) {
                JSONObject c = arr.getJSONObject(i);
                Person p = new Person();
                p.setId(c.getString("id"));
                p.setNama(c.getString("nama"));
                p.setHobi(c.getString("hobi"));
                listData.add(p);
            }
        } catch (JSONException e) {
        }
    } else {
        Platform.runLater(() -> {
            dialog.dialog(Alert.AlertType.ERROR, "Error Connection To Server");
        });
        layoutController.statusConnection = 0;
    }
    return listData;
}

From source file:gui.accessories.GraphPopup.java

private void initAndShowFXGUI() {
    // This method is invoked on the EDT thread
    final JFXPanel fxPanel = new JFXPanel();

    Platform.runLater(new Runnable() {
        @Override// w w  w .  j av a 2  s  . c o  m
        public void run() {
            initFX(fxPanel);
        }
    });
}

From source file:org.eclipse.jubula.rc.javafx.driver.EventThreadQueuerJavaFXImpl.java

/**
 * Executes the given Callable on the JavaFX-Thread and waits for the
 * termination/*from ww w  .  jav a  2 s  . c  o  m*/
 *
 * @param name
 *            a name to identifier which Callable is being executed
 * @param <V>
 *            return value type
 * @param call
 *            the Callable
 * @return
 * @return the return value of the given Callable
 * @throws ExecutionException
 * @throws InterruptedException
 */
public static <V> V invokeAndWait(String name, Callable<V> call) {

    if (Platform.isFxApplicationThread()) {
        try {
            return call.call();
        } catch (Exception e) {
            // the run() method from IRunnable has thrown an exception
            // -> log on info
            // -> throw a StepExecutionException
            Throwable thrown = e.getCause();
            if (thrown instanceof StepExecutionException) {
                if (log.isInfoEnabled()) {
                    log.info(e);
                }
                throw (StepExecutionException) thrown;
            }

            // any other (unchecked) Exception from IRunnable.run()
            log.error("exception thrown by '" + name //$NON-NLS-1$
                    + "':", thrown); //$NON-NLS-1$
            throw new StepExecutionException(thrown);
        }
    }
    try {
        FutureTask<V> task = new FutureTask<>(call);
        Platform.runLater(task);
        return task.get();

    } catch (InterruptedException ie) {
        // this (the waiting) thread was interrupted -> error
        log.error(ie);
        throw new StepExecutionException(ie);
    } catch (ExecutionException ee) {
        // the run() method from IRunnable has thrown an exception
        // -> log on info
        // -> throw a StepExecutionException
        Throwable thrown = ee.getCause();
        if (thrown instanceof StepExecutionException) {
            if (log.isInfoEnabled()) {
                log.info(ee);
            }
            throw (StepExecutionException) thrown;
        }

        // any other (unchecked) Exception from IRunnable.run()
        log.error("exception thrown by '" + name //$NON-NLS-1$
                + "':", thrown); //$NON-NLS-1$
        throw new StepExecutionException(thrown);
    }
}

From source file:Client.Menu.MVCModel.java

@Override
public void handle(String json_stringified) {
    JSONObject obj = JSonFactory.JSON.toJSON(json_stringified);
    String function = obj.getString("function");
    String succes = obj.getString("succes");

    switch (function) {
    case ("register"): {
        if (succes.equals("true")) {
            System.out.println("check");
        } else {//from   w  w w  .j  a  v a  2  s  .  c om
            System.out.println("fail");
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    myControl.Password.setEditable(true);
                    myControl.Username.setEditable(true);
                    myControl.Password.setDisable(false);
                    myControl.Username.setDisable(false);
                    myControl.Register.setDisable(false);
                }

            });
        }
        break;
    }
    case ("login"): {
        if (succes.equals("true")) {
            myManager.Finish(obj.getString("username"));
        } else {
            System.out.println("fail");
        }
    }
    }
}

From source file:fx.DownloadFxApp.java

public static void launchUI() {
    Platform.runLater(new Runnable() {
        @Override/*  w  ww.j av  a2 s  .c o m*/
        public void run() {
            new DownloadFxApp().createScene(new Stage());
        }
    });
}