This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Multiple frames from a parent frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Multiple frames from a parent frame" Watch "Multiple frames from a parent frame" New topic
Author

Multiple frames from a parent frame

Sumit Mhatre
Greenhorn

Joined: Jan 04, 2005
Posts: 3
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

JFrame frame = new JFrame();

You might want to be a little more specific with your question if you want a more specific answer.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jun 13, 2004
Posts: 110
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.


Grails Consultant
http://dangertree.net
Scott Carlson
Greenhorn

Joined: Oct 04, 2005
Posts: 4
^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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 04, 2005
Posts: 4
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 04, 2005
Posts: 4
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Jul 05, 2011
Posts: 12
I have try this demo and he dont work as on tutorial.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Multiple frames from a parent frame