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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software 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
zzynxSr. Software engineerCommented:
yourInternalFrame.addInternalFrameListener( new InternalFrameAdapter() {
    public void internalFrameClosed(InternalFrameEvent e) {
           // do your stuff
    }
});

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

zzynxSr. Software 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
}
CEHJCommented:
JInternalFrame otherFrame = controller.getInternalFrame("theOneIWant");

The controller can keep a Map<String, JInternalFrame>
zzynxSr. Software 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;
  }
zzynxSr. Software engineerCommented:
Forgot the word if:
>> Of course IF you need one of the other JInternalFrame constructors
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);
}

zzynxSr. Software engineerCommented:
Thanx 4 axxepting
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.