aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JtabbedPane & bringing in other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JtabbedPane & bringing in other classes" Watch "JtabbedPane & bringing in other classes" New topic
Author

JtabbedPane & bringing in other classes

Shannon Keough
Greenhorn

Joined: Oct 12, 2001
Posts: 4
I'm writing an application that has 5 or 6 classes. I want to set up the application in a JTabbedPane. At this moment, each class has its own JFrame & contentPane. I have tried to combine all of these into a JTabbedPane with no success. I think I have to extend JFrame in the MainTab class (the class with the JTabbedPane)and extend JPanel for the rest of the classes.
I also have to get rid of the JFrame in each of the other classes and then create an instance of a class within one of the tabs. I can't seem to be able to bring the other classes into one of the panels in MainTab.
I guess My question is how do I create in instance of another class and bring it into a certain tab(panel)
Here the code that i have tried & commented out & rewrote too many times to count.
I'm sure that it is something very stupid that i'm doing wrong.
Unfortunely, at this moment my system is out of resources & won't let me compile this code.

Thanks in Advance
Shannon
import java.sql.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
//declare the public class
public class MainTab extends JFrame
{
public JPanel p1,p2,p3,p4,p5;
public JLabel l1;
public JTabbedPane tp1;
public JFrame f1;
public Container contentPane;
public void draw()
{
tp1=new JTabbedPane();
l1=new JLabel("Test");
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
tp1.addTab("Log-In",p1);
tp1.setSelectedIndex(0);

Client c1=new Client();
tp1.addTab("Client",p2,c1);
tp1.addTab("Property",p4);
tp1.addTab("Search",p5);


f1=new JFrame("Sell My Home Realtors");
contentPane=f1.getContentPane();

contentPane.add(tp1,BorderLayout.CENTER);
//set the frame size and make it visible
f1.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
f1.setSize(700,500);
//f1.pack();
f1.setVisible(true);
}
public static void main(String []args)
{
MainTab mt1=new MainTab();
mt1.draw();
}
}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6


And here is the tab1 class file

How's that??


------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Shannon Keough
Greenhorn

Joined: Oct 12, 2001
Posts: 4
Thanks for the answer but I still can't get it to work. the code is compiling however there is nothing showing in the window. The window is in the upperleft corner. When you maximize the window, you don't see anything but the blank frame.
I think I'll try a CardLayout & see if I can make that work.
Gregg, Thanks a million.
My previous reply was premature. I kept at it and finally got it to work. It seems that to make it work, I had to use this.add to the final panel of the classes I was trying to bring in.
Shannon


[This message has been edited by Shannon Keough (edited October 13, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JtabbedPane & bringing in other classes