0

I want to use ControlsFX StatusBar to display the progress of a long running task. Problem is: In the following code the progress bar displays only once, although the console output is fine every time the task runs. Am I missing something?

public class Main extends Application {

@Override
public void start(Stage primaryStage) {
    try {
        TilePane root = new TilePane();
        Scene scene = new Scene(root, 500, 200);
        Button btn = new Button("Start");
        StatusBar status = new StatusBar();
        status.setPrefWidth(200);

        root.getChildren().addAll(btn, status);
        primaryStage.setScene(scene);
        primaryStage.show();

        StatusTestService service = new StatusTestService();
        status.progressProperty().bind(service.progressProperty());
        status.progressProperty().addListener(inv -> System.out.println(status.getProgress()));
        btn.setOnAction(event -> service.restart());

    } catch(Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    System.out.println(System.getProperty("java.version"));
    launch(args);
}

class StatusTestService extends Service <Void> {

    @Override
    protected Task <Void> createTask() {
        return new Task <Void> () {

            @Override
            protected Void call() throws Exception {
                for (int i = 0; i < 10; i++) {
                    Thread.sleep(100);
                    updateProgress(i, 9);
                }
                return null;
            }
        };
    }       
}
ray_ray_ray
  • 316
  • 1
  • 14
  • What do you mean by saying "displays only once"? I've ran your code sample and it works fine: on every click on "Ok" button progress starts loading again from 0 to 100. – Rawnald Gregory Erickson Aug 08 '17 at 22:31
  • Well, I see the blue bar **only** the first time I run the code, there is no blue bar on subsequent runs, only the text output on the console. I use controlsfx 8.40.13 and Java 8u131 – ray_ray_ray Aug 09 '17 at 06:25

1 Answers1

0

Your code works perfectly using controlsFX 8.40.12 and java 8u144. This behavior may be caused by some sort of a bug in controlsFX. Try to downgrade library to previous version and/or open issue.

  • I can confirm that. I also tested on a machine with ControlsFX 8.40.13 and java 8u77, that was fine, too. The problem is there with java 8u131 / 8u144 **and** the new ControlsFX – ray_ray_ray Aug 09 '17 at 17:25