I have a Progressbar on my JavaFx app. I need to update it from a different thread. That thread will have to provide the progerss value.
My code looks like this
// Task class
public class UpdateProgressBarTask extends Task<Void> {
private double progressValue;
public UpdateProgressBarTask(double value) {
this.progressValue=value;
}
@Override
protected Void call() throws Exception {
this.updateProgress(this.progressValue, 100);
return null;
}
}
//Controller
public void createProgerssTask(double doubleValue) {
UpdateProgressBarTask task = new UpdateProgressBarTask(doubleValue);
progressBar.progressProperty().bind(task.progressProperty());
new Thread(task).run();
}
then I create a new Thread on the controller and from there I have to update the progerssBar
this.timer = Executors.newSingleThreadScheduledExecutor();
this.timer.scheduleAtFixedRate(someFunction(), 0, 33, TimeUnit.MILLISECONDS);
someFunction() {
...
createProgerssTask(double value);
}
I am getting the exception
Exception in thread "pool-2-thread-1" 2 java.lang.IllegalStateException: Not on FX application thread; currentThread = pool-2-thread-1
What am I doing wrong here ? Any help much appreciated