1

How can I change a JavaFX UI but not triggered by user gesture such as a button clicked, but triggered by an outside function (some data received) that calls a function that updates the UI?

I saw in a few questions here that task should resolve this issue, but I did not understand the below example completely: I want to link (observer pattern) a kinesis consumer to fill color of a circle in my GUI. I get that I need to bind the fill property of that circle to consumed record event, but I did not understand what is: task.progressProperty()? in the example code. And to what I change it to, to get a link a record consumed to a circle fill?

Thanks!

import javafx.concurrent.Task;

Task task = new Task<Void>() {
    @Override public Void call() {
        static final int max = 1000000;
        for (int i=1; i<=max; i++) {
            if (isCancelled()) {
               break;
            }
            updateProgress(i, max);
        }
        return null;
    }
};
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();
Elon
  • 11
  • 1
  • I am guessing this is a slim version of your other question. I think you should use `Timeline`. I would check the data from the server every second. If you receive some data, update the GUI. If not, do nothing. https://stackoverflow.com/questions/9966136/javafx-periodic-background-task – SedJ601 Jun 11 '19 at 13:23
  • I am curious if these live charts update will help you. https://stackoverflow.com/questions/22089022/line-chart-live-update. This simulates receiving live data and adding it to a chart using `AnimationTimer` Also https://levelup.gitconnected.com/realtime-charts-with-javafx-ed33c46b9c8d – SedJ601 Jun 11 '19 at 13:26
  • Could you show what the data looks like that you will be receiving from the server? I saw [this](https://stackoverflow.com/questions/56530434/how-to-implement-a-worker-thread-that-will-process-kinesis-records-and-update-gu) post but I don't truly understand what the data will look like that you are getting from AWS. – SedJ601 Jun 11 '19 at 13:32
  • You probably don't want a Task as you'd need to keep running it. With no kinesis experience and just looking at your other post, it looks like you want to create a new interface `KinesisDataListener#onKinesisData` that you can pass into your consumer `new Consumer(database, trans, logic, listener)` which RecordProcessor will have access to. Or you want to add it to your `consumeData(listener)` method. I have no idea which of those two places actually receives the data, but whichever one call `listener.onKinesisData(data)` which should call a RunLater(set circle color). – kendavidson Jun 11 '19 at 17:54
  • After finding something from you possible co-worker, could you post the `monitoringLogic.updateUI()` source? It looks like the other guy says that's where it's trying to happen. – kendavidson Jun 11 '19 at 18:02

0 Answers0