6

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...

joergl
  • 2,850
  • 4
  • 36
  • 42
rak
  • 147
  • 3
  • 4
  • 14

5 Answers5

10

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

Mr. Xymon
  • 1,053
  • 2
  • 11
  • 16
6

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.

Paaske
  • 4,345
  • 1
  • 21
  • 33
2

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

4b0
  • 21,981
  • 30
  • 95
  • 142
Ashraf Gardizy
  • 357
  • 4
  • 9
1

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

mmushtaq
  • 3,430
  • 7
  • 30
  • 47
Arunachalam
  • 51
  • 1
  • 11
0

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 ;)

Jack'
  • 1,722
  • 1
  • 19
  • 27