• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

onClose()

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works with JFrame... at least for me...



-Nate
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic