The user interface cannot be directly updated from a non-application thread. Instead, use Platform.runLater()
, with the logic inside the Runnable object. For example:
Platform.runLater(new Runnable() {
@Override
public void run() {
// Update UI here.
}
});
As a lambda expression:
// Avoid throwing IllegalStateException by running from a non-JavaFX thread.
Platform.runLater(
() -> {
// Update UI here.
}
);