I have Label label
in my FXML Application.
I want this label to change once a second. Currently I use this:
Task task = new Task<Void>() {
@Override
public Void call() throws Exception {
int i = 0;
while (true) {
lbl_tokenValid.setText(""+i);
i++;
Thread.sleep(1000);
}
}
};
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
However nothing is happening.
I don't get any errors or exceptions.
I don't need the value I change the label to in my main GUI thread so I don't see the point in the updateMessage
or updateProgress
methods.
What is wrong?
you need to make changes to the scene graph on the JavaFX UI thread. like this:
Cosmetic change to Sebastian's code.