rak
rak

Reputation: 147

Closing on a single window closes all the frames in java

I would like to make possible the navigation of frames in java.Whenever i close a frame the remaining frames which are also opened get closed;and the entire program stops.

Please help...

Upvotes: 6

Views: 11374

Answers (5)

Ashraf Gardizy
Ashraf Gardizy

Reputation: 389

You can also do that graphicaly. right click on your frame and select properties and from there you can change that like the below picture.

enter image description here

Upvotes: 2

Arunachalam
Arunachalam

Reputation: 51

If you were using swing palette. In frame properties choose default close operation as (Dispose). Follow as per the image given in this solution.

enter image description here

Upvotes: 1

Jack'
Jack'

Reputation: 2526

My problem was that I used a listener found on the basic tutorials :

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

    addWindowListener(l);

I know it's dumb. I didn't see it, but some people might have done the same thing, so I'll just leave this here ;)

Upvotes: 0

Paaske
Paaske

Reputation: 4403

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

If you want to close all frames whenever a single frame closes you can do the following:

You could use a window listener and call System.exit(0); when the JFrame closes, or try setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); on each JFrame. That way your program would close all frames and end.

If you need to perform some tasks before application quits, you should probably use the window listener.

Upvotes: 6

Mr. Xymon
Mr. Xymon

Reputation: 1053

You probably used

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

Maybe you want to use this instead,

   setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

for your reference go to this link

Upvotes: 10

Related Questions