Hi all, I was wondering if it is possible to stop a JFrame or a JDesktopPane from close when the close icon(in the top right hand corner) is pressed?? I know a JInternalFrame can be closed using an InternalFrameListener and you can add a windowListener as follows but what goes inside?? Or is this the correct way of doing this?? addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { // What code goes in here } }); Any help would be great!! Thanks, Patrick.
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
posted
0
for JFrame its easy. type this: setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
Patrick ODonnell
Ranch Hand
Joined: Nov 28, 2001
Posts: 31
posted
0
Thanks that worked lovely!! Can't believe it was that easy
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
posted
0
by the way Patrick, pay attention that if u dont write anything for the close operation the default is to HIDE the frame, not CLOSE it, so it never really ends. to make it close u need to put this: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);