Reputation: 10815
I'm having some problems with the ControlsFX progress bar dialog, could someone post a simple example of using one? I'm having a hard time figuring out how to update the progress bar and what type of Worker I should use.
My Attempt:
Dialogs dialogs = Dialogs.create();
dialogs.nativeTitleBar().title("Updating Population List").masthead("Updating the population table")
.message("The population table is being updated, please be patient.")
.owner(this.addNewPerson.getScene().getWindow()).showWorkerProgress(????);
Upvotes: 1
Views: 3041
Reputation: 677
The ControlsFX progress bar dialog is expecting a Worker. The idea is that a worker updates the bar as progress is made on the work. Remember, though, you can't change live scene graph objects unless your on the JavaFX thread, and you don't want to do long tasks (say those needing a progress bar) on the JavaFX thread. Don't forget to use Platform.runLater() to actually modify the scene graph.
You can find a pretty good example of what you're trying to do here.
http://code.makery.ch/blog/javafx-8-dialogs/
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call()throws InterruptedException {
updateMessage("Initializing Task");
updateProgress(0, 10);
for (int i = 0; i < 10; i++) {
Thread.sleep(300);
//DO BACKGROUND WORK HERE
Platform.runLater(new Runnable {
@Override
public void run() {
//DO LIVE SCENE GRAPH WORK HERE
}
});
updateProgress(i + 1, 10);
updateMessage("Progress Msg");
}
updateMessage("Finished");
return null;
}
};
}
};
//Once you have your worker, you can create the status dialog
Dialogs.create()
.owner(stage)
.title("Progress Dialog")
.masthead("Doing The Thing")
.showWorkerProgress(service);
service.start();
Upvotes: 2