I have a frame which starts a swingTimer to perform a periodic task. The problem is when I close the frame, the task still continues. I want the swingTimer to stop if the close button is pressed.
I have tried specifying EXIT_ON_CLOSE and DISPOSE_ON_CLOSE but these do not work. Does someone know what I should do?
Thanks
Swing Timer has a stop method. You can always call that if the “frame” (JFrame??) ends via a WindowListener.
Also, per my tests, the Timer should stop on its own if the EDT stops. For example:
If this doesn’t help you, then do what I’ve done: post a small compilable and runnable program that demonstrates your problem.