JavaFx 对 SwingUtilities.invokeLater 的响应 [英] JavaFx response to SwingUtilities.invokeLater

查看:24
本文介绍了JavaFx 对 SwingUtilities.invokeLater 的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道 JavaFx 在使用线程时更新 GUI 的方法称为 Task,但代码是否以类似的方式工作,或者是否存在任何差异.让我给你举个挥杆的例子:

So I am aware that JavaFx's method of updating the GUI while using a thread is called Task but does the code work in similar way or are there any differences. let me give you a swing example:

GUI 之外的另一个作为线程运行的类

public void run(){
    while (socket.isConnected()) {
        String x = input.next();
        System.out.println(x);
        mg.updateChat(x)
    }
}

在实际的 GUI 内部

public void updateChat(final String input){
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            txtChat.setText(input); 
        }
    }); 
}

任务是否以完全相同的方式工作?或者是否存在差异,如果存在差异,您将如何修改此代码以在 JavaFx 项目中工作?

Does Task work the exact same way? Or are there differences and if there are how would you modify this code to work in a JavaFx project?

推荐答案

您是否正在寻找 JavaFX 中的 SwingUtil.invokeLater 对应项.如果是,则是:

Are you looking for SwingUtil.invokeLater counterparts in JavaFX. If yes, it is:

Platform.runLater(java.lang.Runnable runnable)

这篇关于JavaFx 对 SwingUtilities.invokeLater 的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆