fx在UI替代品上运行

fx在UI替代品上运行

本文介绍了Java fx在UI替代品上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ayt ..我有点担心,我的问题是是Platform.runlater()是回到UI线程的唯一方法还是有其他选择..

ayt.. i have a little concern here, my question is is Platform.runlater() the only way of getting back to the UI thread or are there any alternatives..

- 例如 -

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'd like to know if there are other means..thanks in advance...

推荐答案

据我所知,没有其他办法。但你可以通过绑定做一些有限的东西来有效地从另一个线程更改UI而不调用 PlatForm.runLater()
示例:

As far as I know there are no other means. But you can through binding do some limited stuff 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;
    }
};

然后在你的GUI中有一个progressBar说:

And then in your GUI have a progressBar say:

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

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

这篇关于Java fx在UI替代品上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:23