CONTROLFX的简单进度条

时间:2014-08-02 01:33:43

标签: java user-interface javafx

我在ControlsFX进度条对话框中遇到了一些问题,是否有人发布使用一个简单示例?我很难搞清楚如何更新进度条以及我应该使用哪种类型的工人。

我的尝试:

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(????);

1 个答案:

答案 0 :(得分:2)

ControlsFX进度条对话框正在等待一名工人。这个想法是,当工作进展时,工人会更新栏。但请记住,除非您在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();
相关问题