Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Closing one of several JInternalFrames

 
Marshal
Posts: 70602
287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just as simple. Take a look at JDesktopPane's methods and you will see it.
 
Campbell Ritchie
Marshal
Posts: 70602
287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found it. Thank you. I had sought high and low in JInternalFrame and never looked at JDesktopPane.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic