import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TabbedExample {
JTabbedPane tpane = null;
private void addTabLater(JTabbedPane tabPane, String tabName, JPanel tabPanel, String tabTip) {
final String ftabName = tabName;
final JPanel ftabPanel = tabPanel;
final String ftabTip = tabTip;
EventQueue.invokeLater(new Runnable() { public void run()
{ tpane.addTab(ftabName, null, ftabPanel, ftabTip); }});
}
public void run() {
JFrame topLevelFrame = new JFrame("Tabbed Example");
topLevelFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
topLevelFrame.setLocation(5,30);
topLevelFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
topLevelFrame.getContentPane().add( topPanel );
tpane = new JTabbedPane();
topPanel.add(tpane, BorderLayout.CENTER);
JPanel tabOne = new JPanel();
tabOne.add(new JButton("One"));
tpane.addTab("Tab One", null, tabOne, "This is tab one");
JPanel tabTwo = new JPanel();
tabTwo.add(new JButton("Two"));
tpane.addTab("Tab Two", null, tabTwo, "This is tab two");
JPanel tabThree = new JPanel();
tabThree.add(new JButton("Three"));
tpane.addTab("Tab Three", null, tabThree, "This is tab three");
topLevelFrame.setVisible(true);
JPanel tabFour = new JPanel();
tabFour.add(new JButton("Four"));
addTabLater(tpane, "Tab Four", tabFour, "This is tab four");
JPanel tabFive = new JPanel();
tabFive.add(new JButton("Five"));
addTabLater(tpane, "Tab Five", tabFive, "This is tab five");
JPanel tabSix = new JPanel();
tabSix.add(new JButton("Six"));
addTabLater(tpane, "Tab Six", tabSix, "This is tab six");
}
static public void main (String argv[]) {
TabbedExample tabbedExample = new TabbedExample();
tabbedExample.run();
}
}