0

I'm using below code for showing progress indicator for loading tasks.I'm using MaskerPane from ControlsFX progress indicator. But when i using the component , maskerpane only showing 1 time..Please suggest a better way for showing progress indicator.

@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();
        }
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
boycod3
  • 5,033
  • 11
  • 58
  • 87
  • Your question isn't very clear. What do you want to achieve from the MaskPane? What is not working? What do you mean by, "maskerpane only showing 1 time" ? – ItachiUchiha May 10 '16 at 09:17
  • sorry for my English.Actually i want to show progress while switching the scenes.Each scenes contain some db operations .So i want show progress indicators.The above code i'm using is only showing the progress once.Next time it wont show any progress bar – boycod3 May 10 '16 at 09:25
  • I do not see you updating the progress by using [updateProgress()](https://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/Task.html#updateProgress-double-double-) on the task. If you do not use it, the progress indicator will never show progress. There are multiple examples showing on how to use it in the javadocs for [Task](https://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/Task.html). – ItachiUchiha May 10 '16 at 09:28
  • Im using MaskerPane's show and hide property. – boycod3 May 10 '16 at 09:30
  • Ahh, my bad. I my opinion it should have worked. Can you try out [this example](https://gist.github.com/TheItachiUchiha/13f8cc637872ebac4385f92cd16075a7) and come back with differences it has wrt your code. – ItachiUchiha May 10 '16 at 09:42

1 Answers1

2

This example can help you.

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

} Source: https://gist.github.com/TheItachiUchiha/13f8cc637872ebac4385f92cd16075a7

I tested it and it works well, so you can adapt it.

Anatole ABE
  • 575
  • 1
  • 7
  • 12