I try to understand how to update a ProgressBar in a multithreaded environment. I'm doing something wrong here but I don't see what it is. This should simply fill up the bar every 3sec but it doesn't:
Task<Void> task = new Task<Void>(){
@Override
public Void call(){
for (int i = 1; i < 10; i++) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(i);
updateProgress(i , 10);
}
return null;
}
};
updProg = new ProgressBar();
updProg.progressProperty().bind(task.progressProperty());
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
What am I missing?
See Question&Answers more detail:os