Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close JButton in JFrame end program non-abruptly

What I am trying to do is make a button that will end the frame as well as end the program but allow other parts, JOGL in this case, to do their own dispose Functions. For instance, when I use the standard close button for the JFrame with EXIT_ON_CLOSE it will end the program but allow JOGL to do its clean up. And if I do System.exit(0) it will not allow any clean up from JOGL.

Essentially:

Custom Close JButton ===> Cleanly end application.

like image 495
MichaelMitchell Avatar asked Feb 17 '26 23:02

MichaelMitchell


1 Answers

How about using WindowAdapter to override the WindowClosing event

 this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            //add your logic for closing here
        }
 });
like image 149
maheeka Avatar answered Feb 19 '26 13:02

maheeka