Hey guys! Im making a small little database program and i want it to have tabs hence the use of a JTabbedPane. I have a porblem though, whenever i make it the tabbedpane in my jframe is in essence a small box thats centered in the middle of the JFrame. This is the code
The problem comes because the class tabbedPane inherits from JPanel. If i were to make it inherit from JFrame it would work fine by making the jframe actually look like a program with a tabs. Anyone know why this happens?
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; /** * * @author Harry */ public class tabbedPane extends JPanel { /** * Creates new form UIf */ //NewData create; JTabbedPane tabbedPane; JPanel customerPane,employeePane, guarantorPane; public tabbedPane() { // create = new NewData(); tabbedPane = new JTabbedPane(); add(tabbedPane); customerPane = new JPanel(new MigLayout()); customerPane.add(new JButton("dfasd")); customerPane.add(new JLabel("First Name:")); employeePane = new JPanel(); guarantorPane = new JPanel(); tabbedPane.addTab("customer", customerPane); tabbedPane.addTab("employee", employeePane); tabbedPane.addTab("guarantor",guarantorPane); //pack(); //add(tabbedPane); } public static void main(String[] args){ tabbedPane a = new tabbedPane(); JFrame frame = new JFrame("Game"); frame.add(a); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
The problem comes because the class tabbedPane inherits from JPanel. If i were to make it inherit from JFrame it would work fine by making the jframe actually look like a program with a tabs. Anyone know why this happens?