Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onClose()

 
kate damond
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works with JFrame... at least for me...



-Nate
 
Terence Doyle
Ranch Hand
Posts: 328
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic