Help with Task - Javafx

Asked

Viewed 76 times

1

Good afternoon, I would like your help with Progressbar and Task in javafx.

I have a progression that have its value altered. 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 this, the code runs without any error, only it arrives at a certain point that my Progressbar (pbStatus) does not update anymore... Stands still at 21 / 91 of 427.

Does anyone know what it might be?

Thanks in advance.

1 answer

1

Solved...

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.