• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JtabbedPane & bringing in other classes

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And here is the tab1 class file

How's that??


------------------
Happy Coding,
Gregg Bolinger
 
Shannon Keough
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Paper beats rock. Scissors beats tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic