I am using javax.swing.Timer to schedule and run events. But it seems to be freezing the GUI. Just wanted to know whether these events are run on a seperate thread or whether I have to do it myself.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Although all Timers perform their waiting using a single, shared thread (created by the first Timer object that executes), the action event handlers for Timers execute on another thread — the event-dispatching thread. This means that the action handlers for Timers can safely perform operations on Swing components. However, it also means that the handlers must execute quickly to keep the GUI responsive.”—
javax.swing.TimerEmphasis added.
Addendum:
SwingWorkerwas designed for just this scenario. In particular, it offers a convenient way to offload work while periodically reporing progress on the EDT.