[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to refer between JInternalFrames.

Posted on 2006-03-28
9
Medium Priority
?
925 Views
Last Modified: 2008-02-26
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.
0
Comment
Question by:svekke
  • 6
  • 3
9 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 16308720
>> 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
 
LVL 37

Accepted Solution

by:
zzynx earned 840 total points
ID: 16308727
yourInternalFrame.addInternalFrameListener( new InternalFrameAdapter() {
    public void internalFrameClosed(InternalFrameEvent e) {
           // do your stuff
    }
});
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16308736
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 16308762
>> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16308774
JInternalFrame otherFrame = controller.getInternalFrame("theOneIWant");

The controller can keep a Map<String, JInternalFrame>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 16308781
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
 
LVL 37

Expert Comment

by:zzynx
ID: 16308785
Forgot the word if:
>> Of course IF you need one of the other JInternalFrame constructors
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16308817
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
 
LVL 37

Expert Comment

by:zzynx
ID: 16309871
Thanx 4 axxepting
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question