2016-05-10 39 views
0

我使用下面的代码来显示加载任务的进度指示器。我使用的是来自ControlsFX进度指示器的MaskerPane。 但是,当我使用的组件,maskerpane只显示1次..请建议一个更好的方式来显示进度指示器。javafx应用程序的进度指示

@FXML 
    private MaskerPane progressPane; 
@FXML 
     private void addMemberSelect() { 
      Task task = new Task<Void>() { 
       @Override 
       protected Void call() throws Exception { 
        progressPane.setVisible(true); 
        return null; 
       } 
       @Override 
       protected void succeeded(){ 
        super.succeeded(); 
        content.setContent(null); 
        ScreensController colllectScreenController = new ScreensController(); 
        colllectScreenController.loadScreen(Screens.ADD_MEMBER); 
        colllectScreenController.setScreen(Screens.ADD_MEMBER); 
        content.setContent(colllectScreenController); 
        progressPane.setVisible(false); 
       } 
      }; 
      new Thread(task).start(); 
     } 
+0

你的问题不是很清楚。你想从MaskPane中获得什么?什么不起作用?你是什​​么意思,“maskerpane只显示一次”? – ItachiUchiha

+0

对不起,我的英语。其实我希望在切换场景时显示进度。每个场景都包含一些数据库操作。所以我想显示进度指标。我使用的上述代码只显示一次进度 一次。显示任何进度栏 – boycod3

+0

我没有看到您使用[updateProgress()]更新进度(https://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/Task.html#updateProgress-double -double-)在任务上。如果您不使用它,进度指示器将永远不会显示进度。有多个示例显示如何在[Task](https://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/Task.html)的javadoc中使用它。 – ItachiUchiha

回答

0

这个例子可以帮助你。

public class MaskerPaneTest extends Application { 
@Override 
public void start(Stage primaryStage) throws Exception { 

    MaskerPane progressPane = new MaskerPane(); 
    progressPane.setVisible(false); 

    Button button = new Button("Show"); 
    button.setOnAction(event -> { 

      Task task = new Task<Void>() { 
       @Override 
       protected Void call() throws Exception { 
        progressPane.setVisible(true); 
        Thread.sleep(2000); 
        return null; 
       } 
       @Override 
       protected void succeeded(){ 
        super.succeeded(); 
        progressPane.setVisible(false); 
       } 
      }; 
      new Thread(task).start(); 
     }); 
    VBox box = new VBox(button, progressPane); 
    box.setAlignment(Pos.CENTER); 
    Scene scene = new Scene(box, 200, 200); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
} 

} 来源:https://gist.github.com/TheItachiUchiha/13f8cc637872ebac4385f92cd16075a7

我测试了它和它的作品,所以你能适应它。