• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about JInternalFrame and JDesktopPane

 
David Crossett
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about MDI applications. Let's say I have a menu button that says "New Window" in a JDesktopPane window (the parent). Let's say that in the ActionEvent listener for this 'New Window' button I have code to create new JInternalFrames (child windows). This all works fine. But here is my question: I'm creating multiple instances of a JInternalFrame with the same variable name. How can this be? How can Java (or more important, me) determine through code which window is which? For example:

This code creates multiple copies of internal frames, all exactly alike, but still separate instances. I don't know my debugger well enough yet to look through this, but don't I have multiple 'frame' variables hanging around out there?
Thank you.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default for the JInternalFrame.setDefaultCloseOperation method is WindowConstants.DISPOSE_ON_CLOSE
Because you made them closable and due to the previous setting, they will not just be hidden when closed --but discarded.
The variable frame is created and goes out of scope after each execution of the method. However, the container to which the internal frames were added will hold a reference pointing to each and takes proper action to save these references regardless the name of the variable that carried the references (frame).
 
David Crossett
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how would I reference these individual windows if I needed to? Would I just create a Vector and then refer to each window by its subscript? Is there a way I can programmatically refer to these instances after they have been created? I want to create the window, display it, THEN draw a shape on it using parameters input on a different JInternalFrame (that can't be closed).
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An instance variable or collection would be appropiate.
Look at the The Java Tutorial for using JInternalFrames
Also consider the following from the javax.swing.DesktopManager API:
JInternalFrame implementations should delegate specific behaviors to the DesktopManager. For instance, if a JInternalFrame was asked to iconify, it should try:
getDesktopPane().getDesktopManager().iconifyFrame(frame);
[ January 05, 2004: Message edited by: Jose Botella ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!