Solved

Loading a frame inside a panel

Posted on 2004-09-04
6
400 Views
Last Modified: 2013-11-23
Hi all

I'm trying to build an application where the main buttons remain on the main frame and a new
(internal)frame shows or loads within the application when one is clicked. In this frame
there might be some input boxes where data is entered and the "next" button is clicked which
will take to another set of functions or just show a confirmation message.

I'm not sure I'm explaining this right so i'll just show a sketch.

http://www.geocities.com/e_freet/roughsketch.gif 

I'm using Netbeans IDE to build the GUI using swing.

It will have a wizard like interface. With around five or six main options and each one will take user to a wizard like interface inside the main application. I'm thinking using internal frames for each one would make the code a little bulky. Is there any way to do this without using internal frames? I mean by loading a frame from outside to a panel or something inside the main frame for each option?

Thanks in advance :)
0
Comment
Question by:efreet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11979712
You should probably use a CardLayout for a wizard:


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

Author Comment

by:efreet
ID: 11979958
Yes, I'm using the card layout on each frame. But I want know if it is possible to use an outside frame with the card layout and load it in a panel or something in the main frame. Because there would be lots of frames and creating lots of internal frames may not be good, I'm thinking.

Any suggestions?

Thanks again :)
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 50 total points
ID: 11980041
You can always put a container (like a JPanel) inside another container (like another JPanel). Apply the layout to the inner JPanel.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 3

Accepted Solution

by:
JohnnyAffa earned 150 total points
ID: 11984210
Container contentPane = this.getContentPane();
contentPane.setLayout(new CardLayout());

// what youll need to do is create subclasses of JPanel so that when you click a button a particular panel is displayed.  of course youll have to create and add them to the contentPane first;  DONT create them when you click a button, only display them ie set them visible

JPanel quickLaunch = new JPanel(null);
quickLaunch.setSize(0,30);// dont need to set the width, its automatically sized

JButtons button[] = new JButton[10];
int buttonSize = quickLaunch.getSize().height;

for ( int index = 0; index < button.length; index++ )
{
     button[index] = new JButton();
     button[index].setBounds(index * buttonSize,0,buttonSize,buttonSize);
// buttons are square and the height of the quickLaunch panel
    button[index].addActionListener(this);
    button[index].addActionCommand(String.valueOf(index));
     quickLaunch.add(button[index]);

}


public void actionPreformed(ActionEvent a)
{
     String id = a.getActionCommand();

     if ( id.eqauls("1") )
            // display panel 1

blah blah blah

// you could convert the id to an int using Integer.parseInt(a.getActionCommand());
}

hope that helped/was what you were looking for

8-)>
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11987043
>> actionPreformed

actionPerformed
0
 

Author Comment

by:efreet
ID: 11987531
Thanks all

I got it now. I created a new panel class

public class externalPanel extends javax.swing.JPanel

with all my buttons and other GUI stuff in it and then created an instance of it in my frame class
externalPanel somepanel = new externalPanel();

and put it in another panel in the main frame class
thepanel.add(somepanel);

Thanks for the help :)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 59
Bot application - advice 3 64
What is the use of Forwarding Class in java 1 37
Java array 10 65
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

730 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