Java javax.swing.Timer-冻结我的GUI.解决方案? [英] Java javax.swing.Timer - freezing my GUI. Solution?

查看:52
本文介绍了Java javax.swing.Timer-冻结我的GUI.解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用javax.swing.Timer运行的任务.它每几分钟执行一次.该任务需要一两秒钟,并且冻结了我的GUI.

I have a task running using javax.swing.Timer. It executes once every few minutes. The task takes a second or two, and it is freezing my GUI.

该如何解决?

推荐答案

Timer任务在Event Dispatching线程上执行,因此当您的任务运行时,不会发生其他任何摆动事件,并且gui将冻结.对于如此长的任务,您应该创建一个单独的线程,或者使用SwingWorker.

Timer tasks are executed on the Event Dispatching thread so while your task is running, no other swing event can happen and your gui will freeze. You should make a separate thread for such a long task or use SwingWorker.

有关更多详细信息,请参见问题.

See this question for more details.

这篇关于Java javax.swing.Timer-冻结我的GUI.解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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