Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JInternal Frames under JMenu

 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have designed a JMenu. On clicking each JMenuItem, a JInternal FRAME is invoked (because only JInternal Frame sits perfectly under JMenu). I have a button in the JInternal Frame which on invoked should open another JInternalFrame. I don't think it is possible
I tried invoking JFrame from JInternalFrame. The JFrame was opened but an exception was thrown so I rejected that idea. Is there any other alternative?.
with warm regards,
Arun.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JInternalFrame should be able to have another JInternalFrame in it. Why didn't you do that?
You can't use a JFrame inside a JInternalFrame, because a JFrame is a heavywieght component - it has a peer on the operating system, and as such needs to be ONLY an outermost container. The main difference that JInternalFrame has is that is does NOT have that native peer, and therefore can be contained in another container.
 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the response. I am happy to say that I have acheived the desired result. I am here giving out the rough analysis of the code. Before that I would like to state what I precisely I need. I have designed a JMenu and on clicking each JMenuItem,the first JInternalFrame is opened and when a button is clicked a second JInternalFrame should be opened. This is how I went about it
1. Declared a JFrame containing a static Desktop and containing the JMenuItems. On clicking a particular JMenuItem, the first JInternalFrame is opened
public class MainFrame extends JFrame
{
static JDesktopPane desktop;
MainFrame()
{
MenuItem.addActionListener(new ActionListener()
{
InternalFrame1 fr1 = new InternalFrame1();
// invoking the first JInternalFrame
desktop.add(fr1);
fr1.setVisible(true);
fr1.show(true);
}
}// end of constructor MainFrame
} // end of class MainFrame
2. Declaring the the first JInternalFrame,and inside when a button is clicked a second JInternalFrame should be opened
public class InternalFrame1 extends JInternalFrame
{
InternalFrame1()
{
super("title",false,true,false,false);
this.setFrameIcon(null);
// remaining code
}// end of constructor InternalFrame1

public void actionPerformed(ActionEvent evt)
{
InternalFrame2 fr2 = new InternalFrame2();
// invoking the second JInternalFrame
fr2.setVisible(true);
MainFrame.desktop.add(fr2);
fr1.show();

}// end of actionPerformed
} // end of class InternalFrame1
3.The second JInternalFrame2
public class InternalFrame2 extends JInternalFrame
{
InternalFrame2()
{
super("title",false,true,false,false);
this.setFrameIcon(null);
// remaining code
}// end of constructor InternalFrame2
} // end of class InternalFrame2

with warm regards ,
Arun.





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic