All manipulations with JavaFX nodes in the graphics of the active scene must be performed in the JavaFX application stream, otherwise your program may not work correctly.
JavaFX throws an IllegalStateException: Not on FX application thread exception when trying to change the attributes of scene graph nodes from a JavaFX application thread. Even if you do not get an IllegalStateException, you should not change the nodes of the scene graph from the JavaFX application stream, because if your code can fail unexpectedly.
Replace the code that manipulates the scene graph nodes in Platform.runLater to allow the JavaFX system to run code in the JavaFX application thread.
For example, you can fix your program with the following code:
Platform.runLater(new Runnable() { @Override public void run() { label.setText(""); } }
source share