Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDesktopPane

 
Michael Alan Brown
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is it possible to add a window listener to JDesktop so I can give and option to close the window so the program is not closed by mistake.

Thanks
Mike
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's JDesktop? There's no such class in the standard API
 
Michael Alan Brown
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, thanks for responding, I mean JDesktopPane.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And by JDesktopPane, I'm sure you mean JInternalFrame

See what methods the latter has? Most notably one that starts with "add" and ends with "Listener"? It's the closing event that will be triggered just before it is actually closed. Don't forget to set the right default close operation (hint hint hint); the default is no longer the one you want.
 
Michael Alan Brown
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help but I still a bit stuck.

What I am trying to do is close the window that contains all the internal frames not the internal frames. This will let me put up a message before all the frames are closed.

Sorry, if this is really obvious.


Mike
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
Please read http://faq.javaranch.com/java/UseAMeaningfulSubjectLine

You can edit the title by clicking on the button
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The window with the JDesktopPane in it is probably a JFrame and JDialog. My advice basically still holds, only you will use a WindowListener instead of an InternalFrameListener, using the windowClosing event. You still need to set the proper default close operation.
 
Michael Alan Brown
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all you responses but I still having the problem. Even when I set the close option to do nothing the window still closes and I can not add an internal frame or window listener


 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame extends Window so it has method addWindowListener. I don't see you calling it anywhere.
 
Michael Alan Brown
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help. I don't know what the problem was but eclipse is now letting me add the listener.

Thanks
Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic