Close in one window closes all frames in java

I would like to make it possible to navigate frames in java. When I close the frame, the rest of the opening frames will be closed and the whole program will stop.

Please, help...

+4
source share
4 answers

You probably used

//this will terminate or exit your application setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

Perhaps you want to use this instead,

  setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); 

refer to this link for reference

+8
source

If you want to close only one frame, you should do something like this: setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)

If you want to close all frames whenever one frame is closed, you can do the following:

You can use the window listener and call System.exit(0); when the JFrame closes, or try setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); on every JFrame . Thus, your program will close all frames and end.

If you need to complete some tasks before shutting down the application, you should probably use a window listener.

+5
source

My problem was that I used the listener found in the main tutorials:

 WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); 

I know this is stupid. I have not seen this, but some people may have done the same, so I will just leave it here;)

0
source

If you use the swing palette. In the properties of the frame, select the default close operation as (Dispose). Follow the image given in this solution.

enter image description here

0
source

Source: https://habr.com/ru/post/1403871/


All Articles