Help with Task - JavaFX

1

Good afternoon, I would like your help with ProgressBar and Task in javaFX.

I have a progressBar that has its value changed. I have the following code:

Task task = new Task<Integer>() {
        @Override
        protected Integer call() throws Exception {
            for (int i = 1; i <= 427; i++) {
                if (isCancelled()) {
                    break;
                }
                updateProgress(i, 427);
                updateMessage("Atualizando: "+i+" de "+427);
                Thread.sleep(1000);
            }
            return 427;
        }
    };
    pbStatus.setProgress(1);
    pbStatus.progressProperty().bind(task.progressProperty());
    lbProgresso.textProperty().bind(task.messageProperty());
    ExecutorService executor = Executors.newFixedThreadPool(427, new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setDaemon(true);
                    return t;
                }
            });
    executor.execute(task);

The problem is as follows, the code runs without any error, but it arrives at a certain moment that my ProgressBar (pbStatus) no longer updates ... It stands at 21/91 out of 427.

Does anyone know what it can be?

Thank you in advance.

    
asked by anonymous 22.06.2015 / 21:27

1 answer

1

Resolved ...

    Platform.runLater(new Runnable() {
  @Override
    public void run() {
      lbProgresso.textProperty().bind(task.messageProperty());
      pbStatus.progressProperty().bind(task.progressProperty());
    }
});
    
24.06.2015 / 17:49