我在使用 ControlsFX 进度条对话框时遇到一些问题,有人可以发布一个简单的使用示例吗?我很难弄清楚如何更新进度条以及我应该使用什么类型的 Worker。
我的尝试:
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(????);
最佳答案
ControlsFX 进度条对话框需要一个 Worker。这个想法是,工作人员随着工作的进展更新进度条。但请记住,除非您在 JavaFX 线程上,否则您无法更改实时场景图对象,并且您不想在 JavaFX 线程上执行长任务(比如需要进度条的任务)。不要忘记使用 Platform.runLater() 来实际修改场景图。
您可以在这里找到一个很好的示例来说明您正在尝试做的事情。
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();
关于java - ControlsFX 的简单进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25090821/