Contents

Swinging Duke
Feedback Button
Left ArrowRight Arrow

 

The TabbedPane API

In Swing, a JTabbedPane object is a component that displays a set of labels representing a set of child components. By selecting the tabbed label that represents a component, the user can view any child component in the set.

The labels displayed by a TabbedPane component resemble the tabs on a set of file folders. When the user clicks one of the tabs displayed inside a TabbedPane component, the child component associated with the selected tab "opens" so the user can view it.Meanwhile, all other tabs remain visible.

By clicking the various tabs displayed inside a TabbedPane component, the user can view one child component at a time.

This specification explains how TabbedPane components are implemented in Swing. To see an example of how Swing's TabbedPane component works, run the SwingSet sample program in the examples folder that is provided with Swing.


Features of the TabbedPane Component

Swing supports the following features in TabbedPanes:


The SingleSelectionModel

In Swing, a SingleSelectionModel is used to represent the state of a TabbedPane component. A ChangeListener can be registered with the TabbedPane to allow notification of the selection changing.

The SingleSelectionModel is used to represent, at most ,one indexed selection:

public interface SingleSelectionModel {
    public int getSelectedIndex();
    public void setSelectedIndex(int index);
    public void clearSelection();
    void addChangeListener(ChangeListener listener);
    void removeChangeListener(ChangeListener listener);
}


Tabbed Panes and Events

TabbedPanes are a source of ChangeEvents. By registering itself as a ChangeListener on a tabbed pane, an object ensures that it will be notified when the selected tab has changed


The JTabbedPane Class Definition

This is the definition of the JTabbedPane class:

public class JTabbedPane extends JComponent {
    public JTabbedPane() {}

    public TabbedPaneUI getUI() {}
    public void setUI(TabbedPaneUI ui) {}
    public void updateUI() {}

    public void addChangeListener(ChangeListener l) {}
    public void removeChangeListener(ChangeListener l) {}
    public SingleSelectionModel getModel() {}
    public void setModel(SingleSelectionModel model) {}
    public int getSelectedIndex() {}
    public void setSelectedIndex(int index) {}

    public void addTab(String title, Icon icon, Component component) {}
    public void removeTabAt(int index) {}
    public int getTabCount() {}
    public String titleAt(int index) {}
    public Icon iconAt(int index) {}
    public Component componentAt(int index) {}
}

Arrows


Version 0.5. Last modified 10/1/97.
Copyright © 1995-97 Sun Microsystems, Inc. All Rights Reserved.

Sun's Home Page