I have the following piece of code:
@FXML public void initialize() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
for(int i=0 ; i<10 ;i++) {
Thread.sleep(1000);
exampleButton.setText(String.valueOf(i));
}
}catch(Exception e) {}
}
});
}
Which should obviously change the text of the button every second.
According to this question, I put the sleep
and the setText
into a Platform.runLater
-block, since GUI-modifications should not be done from the main thread. But my GUI is still freezing.
Why does this happen?