File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes onClose() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "onClose()" Watch "onClose()" New topic
Author

onClose()

kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Hi,
I know this has been explained at length before but I don't get it ! I have a JFrame, and when it is created and initialised, I set

Then, for the window Closing event, I have a JOptionPane ConfirmDialog box pop up which asks the user if they want to save before closing.
Whichever option they choose .... it closes ! It should NEVER close ... any ideas ?
Cheers,
Kate
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
You told the Frame to <b>do nothing</b> on closing NOT <b>not to close</b>!
As far as I know you cannot stop a top-level container from closing.
You could assign an OptionPane to the windowClosing(WindowEvent e) event - which is generated before it dissappears and then allow the user to cancel - though you'd have to capture the close event and consume it or something similar.
You can configure a JInternalFrame as not closable.
Hope that helps,


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It works with JFrame... at least for me...



-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Yes Nathan,
You're absolutely right, of course. I suppose I should have tested some code before mouthing off.
Well I've learned something new today
Terry
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Hmm, but it didn't work for me !!!
I'm developing it in Visual Age, so it takes some chopping about to post code. Maybe I'll have to do that, cos I definitely set the default Close operation to do nothing, and it just goes off and closes all by itself, no matter what I tell it to do...
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Make sure that Visual Age isn't inserting any propriatary API calls (i.e. com.ibm.*) if you are generating code, and also see if any other listeners are being added to your frame... even if you set your frame to do nothing on close, if there is a listener, or if the frame uses processWindowEvent(), it will still exit.

-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onClose()