How to refer between JInternalFrames.

Hello,

I'm trying to open a JinternalFrame when pressing a button in another JinternalFrame. In order to accomplish this I need to add a JDesktopPane to the JinternalFrame which opens the other JInternalFrame.
To start I set the visibility of this JDesktopPane to false. And when I press the Edit button to open the JInternalFrame I set the visibilty to true and add the other JInternalFrame to this JDesktopPane.
But how do I set the visibility of this JDesktopPane to false when I close or dispose the JInternalFrame I opened in order to edit the data?
How do I refer to the parent JinternalFrame from the child JInternalFrame?


Thanx in advance.
svekkeAsked:
Who is Participating?
 
zzynxSoftware engineerCommented:
yourInternalFrame.addInternalFrameListener( new InternalFrameAdapter() {
    public void internalFrameClosed(InternalFrameEvent e) {
           // do your stuff
    }
});
0
 
zzynxSoftware engineerCommented:
>> In order to accomplish this I need to add a JDesktopPane to the JinternalFrame which opens the other JInternalFrame.
Shouldn't you add a JDesktopPane to your main JFrame and open all JInternalFrames form there?

>> how do I set the visibility of this JDesktopPane to false when I close or dispose the JInternalFrame
By adding an InternalFrameListener
0
 
CEHJCommented:
The pattern you need is to use a controller class. This can be the class that owns the desktop pane. Pass requests to *it* for the other frame
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
zzynxSoftware engineerCommented:
>> How do I refer to the parent JinternalFrame from the child JInternalFrame?
You could do it by simply passing it.
But I believe you better pass the JDesktopPane or even better the main JFrame.

public class MyInternalFrame extends JInternalFrame {

         private JDesktopPane desktopPane = null;    // <<< Make your choice between this
         private JFrame mainFrame = null;                   // <<< or this

         public MyInternalFrame(JDesktopPane dp) {
              desktopPane = dp;
         }

         OR

        public MyInternalFrame(JFrame f) {
             mainFrame = f;
        }


        Then further on (in all methods you want) you can use mainFrame or desktopPane as you need
}
0
 
CEHJCommented:
JInternalFrame otherFrame = controller.getInternalFrame("theOneIWant");

The controller can keep a Map<String, JInternalFrame>
0
 
zzynxSoftware engineerCommented:
Of course if you don't like my recommendation, you can pass the parent JInternalFrame too:

public class MyInternalFrame extends JInternalFrame {

         private JInternalFrame parentInternalFrame = null;

         public MyInternalFrame(JInternalFrame parent) {
              parentInternalFrame = parent;
         }


        Then further on (in all methods you want) you can use parentInternalFrame as you need
}

Remark:
Of course you need one of the other JInternalFrame constructors, just add an extra parameter:

  public MyInternalFrame(JInternalFrame parent, String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) {
      super(title, resizable, closable, maximizable, iconifiable);
      parentInternalFrame = parent;
  }
0
 
zzynxSoftware engineerCommented:
Forgot the word if:
>> Of course IF you need one of the other JInternalFrame constructors
0
 
CEHJCommented:
As you create your JInternalFrame:

JFrame editFrame = new JInternalFrame();
...
frameMap.put("editFrame", editFrame);

Of course, the controller can use its own Map too

The following convenience method can be used in the controller:


public JInternalFrame getInternalFrame(String name) {
    return (JInternalFrame)frameMap.get(name);
}

0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.