Java javax.swing.Timer - freezing my GUI. Solution

2019-03-02 20:14发布

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.

What can I do to fix this?

标签: java swing timer
2条回答
Melony?
2楼-- · 2019-03-02 20:41

The task may be taking more that 2 seconds.. Does the task require access to GUI? If not use separate thread. The specific part of the task which require GUI access, can use SwingWorker to update the GUI.

查看更多
成全新的幸福
3楼-- · 2019-03-02 20:45

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.

查看更多
登录 后发表回答