简体   繁体   中英

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM