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 Closing one of several JInternalFrames Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Closing one of several JInternalFrames" Watch "Closing one of several JInternalFrames" New topic
Author

Closing one of several JInternalFrames

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37960
    
  22
You know when you have a JFrame, with a JDesktopPane in, then you can have several JInternalFrames open?
You can close one JInternalFrame by clicking its [X] close button, but I was thinking it is more elegant to have a "closeItem" in a menu. I have worked out how to get a "closeItem" into a JMenuBar, and can get it to appear on screen, but what is the best way to close one JInternalFrame?
I have tried the getSelectedFocus() method [or something like that], which gets the JRootPane of the JFrame, so that isn't helpful.
In Horstmann's book it says that you have to get an array JInternalPane[], then iterate through it to find the object with focus, then . . . thatInternalPane.setClosed(true);
I seems a complicated way to do it; does anybody know anything easier or more elegant? In C# we were told to put about two lines in the listener, and it took me about 30 seconds to realise you could write "this.ActiveMdiChild.close();". Is it really more complicated in Java?

CR
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
It's just as simple. Take a look at JDesktopPane's methods and you will see it.


There is no emoticon for what I am feeling!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37960
    
  22
Found it. Thank you. I had sought high and low in JInternalFrame and never looked at JDesktopPane.
 
Consider Paul's rocket mass heater.
 
subject: Closing one of several JInternalFrames
 
Similar Threads
How to set focus on one of the two JInternalFrame
Events from inner components.
Has anyone used JavaHelp?
Putting a JTabbedPane in a JInternalFrame
A TOUGH question on JInternal Frame