No effect of setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

+1 pratt 15 · July 30, 2014
Hey anybody noticed that , when using GUI's in java if you do not declare
obj.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
then the Frame still runs and close when you click the "X" button. Can anybody explain me why is it so??

:angel::angel:

Post a Reply

Replies

Oldest  Newest  Rating
+1 Mathias Frits Rørvik · July 30, 2014
Because it does not terminate the java virtual machine, unless you have JFrame.EXIT_ON_CLOSE.
+1 Brandon Elliott · July 30, 2014
Your question is a little confusing. Are you saying that your program works the same whether or not you set the default close operation?
0 pratt 15 · July 30, 2014
@Brandon Elliott 

Yup...program runs even if you do not put "setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );"
in it.....you can try it on your machine.:ermm:
0 Brandon Elliott · July 30, 2014
Yes it will still run but it won't actually close if you click the close button. It will still be running but the frame will be hidden, as Brano explained

So for example say you don't set EXIT_ON_CLOSE and you run the program and "close" it 100 times, there will be 100 processes still running in the background, which is not good.
  • 1

Java / Android Development

107,205 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator