Reputation: 339
I have a single frame created using Netbeans GUI builder when I view the frame properties one of the first options is default close operation the options listed are: DISPOSE_ON_CLOSE
, HIDE_ON_CLOSE
, DO_NOTHING_ON_CLOSE
& EXIT_ON_CLOSE
I understand the middle two but, whats the difference between DISPOSE_ON_CLOSE
and EXIT_ON_CLOSE
? I have tried testing both but to me they do the same thing to me
Upvotes: 12
Views: 36485
Reputation: 95
exit on close permanently closes the window for that instance while dispose on close doesn't.
Upvotes: -1
Reputation: 95
DISPOSE_ON_CLOSE - Disposes the window when it's closed. You cannot redisplay the window, although the object window is still available in the memory
Upvotes: 1
Reputation: 8959
If you have a few JFrames open and you close the one that is set to EXIT_ON_CLOSE
then all of the frames will be closed.
The opposite applies to the one with the DISPOSE_ON_CLOSE
i.e. only it will be closed
Upvotes: 9
Reputation: 30042
EXIT_ON_CLOSE
will terminate the program.
DISPOSE_ON_CLOSE
will call dispose()
on the frame, which will make it disappear and remove the resources it is using. You cannot bring it back, unlike hiding it.
See aslo JFrame.dispose() vs System.exit()
Upvotes: 15