import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// Fri Oct 15 18:07:43 EST 2004
// Written by Sean R. Owens, sean at guild dot net, released to the
// public domain.  Share and enjoy.  Since some people argue that it is
// impossible to release software to the public domain, you are also free
// to use this code under any version of the GPL, LPGL, or BSD licenses,
// or contact me for use of another license.

// Very simple example of using JTabbedPane.
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);}
        // For some reason I don't understand, if I just use 0,0 here
        // (the top left of the screen), xwin-32 puts the window
        // slightly off the screen to the top and the left.

        JPanel topPanel = new JPanel();
        topPanel.setLayout( new BorderLayout() );
        topLevelFrame.getContentPane().add( topPanel );

        tpane = new JTabbedPane();
        topPanel.add(tpane, BorderLayout.CENTER);

        // The tabbed pane is not visible yet, so we don't have to
        // worry about Swing and multithreading now.  (If I'm
        // incorrect on this, someone please let me know.)
        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");

        // Note, DON'T use .pack() - or we undo all the
        // setSize/setLocation crap above.

        // We've made the tab visible, so now we can't just 'addTab'.
        // If we do, we'll get occasional, hard to reproduce, weird
        // exceptions.  So instead we use invokeLater, which we've
        // isolated off in a little method above, 'addTabLater'.
        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();;