So I have a swing application, a button, when pressed, will launch a worker thread. If the main window is closed it the JVM is still running with the worker thread going on uninterrupted and indefinitely. I want the worker thread to die when the window is closed.
Share
If you want the entire application to terminate when the window is closed you can use this:
If you just want to stop the worker thread only and maybe do other stuff. You can register a WindowListener on the frame and in the onWindowClosing callback, you can check the event type and do whatever you wish.