Thursday, December 2, 2010

Closing a Swing Application

Just calling toplevel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); is not good enough.
There could be other frames still alive, esp if you are using a third party library.
So your JVM is still running. Here is how you fix it..
Get all the frames that are currently running and dispose each of them

Frame[] frames = toplevel.getFrames();

for(int i=0;i
Frame frame = frames[i];
frame.dispose();
}
-Sonu

No comments: