Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple frames from a parent frame

 
Sumit Mhatre
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to open multiple frames from a parent frame. I am creating an application. In that I've one main frame along with menus. Using those menus I'm calling another frames in that frame. How to call other frames in the main parent frame ?
Any suggestion / code ...
[ July 27, 2005: Message edited by: Sumit Mhatre ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame frame = new JFrame();

You might want to be a little more specific with your question if you want a more specific answer.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you open your parent frame? Opening a second frame is no different really. In your event handler for whatever menu item, create a new instance of whatever frame you want and make it visible.
 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to have one main frame of the application and the menu selections are just going to change what is going to be displayed in the frame, I suggest you only create one frame. Then you create custom panel classes to be displayed within that frame. When a menu item is chosen, call a method within the frame to reload with a different panel specified by the menu selection. If you create all the panels upon frame construction, you should be able to save their states even when they aren't being displayed.

Another simpler option might be to use a JTabbedPane and forget about using the menu to navigate the application.
 
Scott Carlson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^bump^

This is exactly what I am looking to do. I am new to Java but I am in a tight bind in learning how to do a GUI from Java by next week. I have been working with JBuilder and the way I want to do my GUI is to have a menu that will display the different panels the user chooses.

Does anyone have an example of this that I could see?

Any advice or tutorials someone might have that talks about calling multiple panels in a single Frame or Window would be great.

Thanks in advance,

Scott
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> the way I want to do my GUI is to have a menu that will display the
> different panels the user chooses

CardLayout is perfect for this scenario.
 
Scott Carlson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should of been more specific sorry. I want the user to open up new windows or panels when he or she selects a certain menubar option.

Scott
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want multiple windows (frames) showing, reply #1 in this thread
is the start of what you have to do.

if you only want the one window (frame) showing, but the panel displayed is
dependent on user (menu) selection, CardLayout is your best option.
 
Scott Carlson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. I will try and find something on how cardlayout works. If anyone can point me to a good tutorial on this or some advice as to how to set this up that would be great. Otherwise, thanks again.

Scott
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should get most of your info here

http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html


here's a simple demo

 
Boba Jeff
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have try this demo and he dont work as on tutorial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic