*
The moose likes Swing / AWT / SWT and the fly likes JDesktopPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDesktopPane" Watch "JDesktopPane" New topic
Author

JDesktopPane

Michael Alan Brown
Greenhorn

Joined: Jan 07, 2010
Posts: 8
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

Joined: May 03, 2008
Posts: 4664
    
    5

What's JDesktop? There's no such class in the standard API


luck, db
There are no new questions, but there may be new answers.
Michael Alan Brown
Greenhorn

Joined: Jan 07, 2010
Posts: 8
Sorry, thanks for responding, I mean JDesktopPane.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Alan Brown
Greenhorn

Joined: Jan 07, 2010
Posts: 8
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

Michael,
Please read http://faq.javaranch.com/java/UseAMeaningfulSubjectLine

You can edit the title by clicking on the button


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

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

Joined: Jan 07, 2010
Posts: 8
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

Joined: Oct 27, 2005
Posts: 19784
    
  20

JFrame extends Window so it has method addWindowListener. I don't see you calling it anywhere.
Michael Alan Brown
Greenhorn

Joined: Jan 07, 2010
Posts: 8
Thanks for all the help. I don't know what the problem was but eclipse is now letting me add the listener.

Thanks
Michael
 
jQuery in Action, 2nd edition
 
subject: JDesktopPane