JavaFx对SwingUtilities.invokeLater的响应 [英] JavaFx response to SwingUtilities.invokeLater
本文介绍了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屋!
查看全文