Saturday, April 1, 2017

JavaFX | Make an update of the UI | Platform.runlater

In javaFX any update of the user interface should be done by the javaFX application thread. Any other thread trying to update the UI will crash the application. So if you have a multi threaded application every line of code that update the UI should be wrapped in Platform.runLater block like this:
Platform.runLater(new Runnable() {
    @Override
    public void run() {
        // Update UI here.
    }
});
Or using lambda Expression:
Platform.runLater(
  () -> {
    // Update UI here.
  }
);

No comments:

Post a Comment