Java fx runs on UI alternatives

ayt .. I have a little problem here, my question is that Platform.runlater () is the only way to go back to the UI thread or are there any alternatives.

- eg,

new Thread(new Runnable() {

        @Override
        public void run() {
            // i do something slick here

            Platform.runLater(new Runnable() { // is this the only way??

                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                TextField txt =new TextField(" internal server error -Re-try");
                                root.getChildren().add(txt);
                            }
                        });

        }
    }).start();;

      

I would like to know if there are other remedies ... in advance ...

0


source to share


1 answer


As far as I know, there are no other means. But you can use binding to do some limited things to effectively change the UI from another thread without calling PlatForm.runLater()

Example:

Task task = new Task<Void>() {
    @Override public Void run() {
         for (int i=0; i<100; i++) {
            updateProgress(i, 100);
        }
        return null;
    }
};

      



And then there is a progressBar in your GUI:

ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();

bar.progressProperty().bind(task.progressProperty());

      

+1


source







All Articles