FileDocCategorySizeDatePackage
JTabbedPane.javaAPI DocJava SE 5 API71002Fri Aug 26 14:57:56 BST 2005javax.swing

JTabbedPane

public class JTabbedPane extends JComponent implements Serializable, SwingConstants, Accessible
A component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon. For examples and information on using tabbed panes see How to Use Tabbed Panes, a section in The Java Tutorial.

Tabs/components are added to a TabbedPane object by using the addTab and insertTab methods. A tab is represented by an index corresponding to the position it was added in, where the first tab has an index equal to 0 and the last tab has an index equal to the tab count minus 1.

The TabbedPane uses a SingleSelectionModel to represent the set of tab indices and the currently selected index. If the tab count is greater than 0, then there will always be a selected index, which by default will be initialized to the first tab. If the tab count is 0, then the selected index will be -1.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

beaninfo
attribute: isContainer true description: A component which provides a tab folder metaphor for displaying one component from a set of components.
version
1.140 04/02/04
author
Dave Moore
author
Philip Milne
author
Amy Fowler
see
SingleSelectionModel

Fields Summary
public static final int
WRAP_TAB_LAYOUT
The tab layout policy for wrapping tabs in multiple runs when all tabs will not fit within a single run.
public static final int
SCROLL_TAB_LAYOUT
Tab layout policy for providing a subset of available tabs when all the tabs will not fit within a single run. If all the tabs do not fit within a single run the look and feel will provide a way to navigate to hidden tabs.
private static final String
uiClassID
protected int
tabPlacement
Where the tabs are placed.
private int
tabLayoutPolicy
protected SingleSelectionModel
model
The default selection model
private boolean
haveRegistered
protected ChangeListener
changeListener
The changeListener is the listener we add to the model.
Vector
pages
protected transient ChangeEvent
changeEvent
Only one ChangeEvent is needed per TabPane instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".
Constructors Summary
public JTabbedPane()
Creates an empty TabbedPane with a default tab placement of JTabbedPane.TOP.

see
#addTab


                      
      
        this(TOP, WRAP_TAB_LAYOUT);
    
public JTabbedPane(int tabPlacement)
Creates an empty TabbedPane with the specified tab placement of either: JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane.LEFT, or JTabbedPane.RIGHT.

param
tabPlacement the placement for the tabs relative to the content
see
#addTab

	this(tabPlacement, WRAP_TAB_LAYOUT);
    
public JTabbedPane(int tabPlacement, int tabLayoutPolicy)
Creates an empty TabbedPane with the specified tab placement and tab layout policy. Tab placement may be either: JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane.LEFT, or JTabbedPane.RIGHT. Tab layout policy may be either: JTabbedPane.WRAP_TAB_LAYOUT or JTabbedPane.SCROLL_TAB_LAYOUT.

param
tabPlacement the placement for the tabs relative to the content
param
tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
exception
IllegalArgumentException if tab placement or tab layout policy are not one of the above supported values
see
#addTab
since
1.4

        setTabPlacement(tabPlacement);
	setTabLayoutPolicy(tabLayoutPolicy);
        pages = new Vector(1);
        setModel(new DefaultSingleSelectionModel());
        updateUI();
    
Methods Summary
public java.awt.Componentadd(java.awt.Component component)
Adds a component with a tab title defaulting to the name of the component which is the result of calling component.getName. Cover method for insertTab.

param
component the component to be displayed when this tab is clicked
return
the component
see
#insertTab
see
#removeTabAt

	if (!(component instanceof UIResource)) {
            addTab(component.getName(), component);
	} else {
	    super.add(component);
	}
        return component;
    
public java.awt.Componentadd(java.lang.String title, java.awt.Component component)
Adds a component with the specified tab title. Cover method for insertTab.

param
title the title to be displayed in this tab
param
component the component to be displayed when this tab is clicked
return
the component
see
#insertTab
see
#removeTabAt

	if (!(component instanceof UIResource)) {
            addTab(title, component);
	} else {
	    super.add(title, component);
	}
        return component;
    
public java.awt.Componentadd(java.awt.Component component, int index)
Adds a component at the specified tab index with a tab title defaulting to the name of the component. Cover method for insertTab.

param
component the component to be displayed when this tab is clicked
param
index the position to insert this new tab
return
the component
see
#insertTab
see
#removeTabAt

	if (!(component instanceof UIResource)) {
            // Container.add() interprets -1 as "append", so convert
            // the index appropriately to be handled by the vector
            insertTab(component.getName(), null, component, null, 
                      index == -1? getTabCount() : index);
	} else {
	    super.add(component, index);
	}
        return component;
    
public voidadd(java.awt.Component component, java.lang.Object constraints)
Adds a component to the tabbed pane. If constraints is a String or an Icon, it will be used for the tab title, otherwise the component's name will be used as the tab title. Cover method for insertTab.

param
component the component to be displayed when this tab is clicked
param
constraints the object to be displayed in the tab
see
#insertTab
see
#removeTabAt

	if (!(component instanceof UIResource)) {
            if (constraints instanceof String) {
                addTab((String)constraints, component);
            } else if (constraints instanceof Icon) {
                addTab(null, (Icon)constraints, component);
            } else {
                add(component);
	    }
        } else {
	    super.add(component, constraints);
	}
    
public voidadd(java.awt.Component component, java.lang.Object constraints, int index)
Adds a component at the specified tab index. If constraints is a String or an Icon, it will be used for the tab title, otherwise the component's name will be used as the tab title. Cover method for insertTab.

param
component the component to be displayed when this tab is clicked
param
constraints the object to be displayed in the tab
param
index the position to insert this new tab
see
#insertTab
see
#removeTabAt

	if (!(component instanceof UIResource)) {

            Icon icon = constraints instanceof Icon? (Icon)constraints : null;
            String title = constraints instanceof String? (String)constraints : null;
            // Container.add() interprets -1 as "append", so convert
            // the index appropriately to be handled by the vector
            insertTab(title, icon, component, null, index == -1? getTabCount() : index);
	} else {
	    super.add(component, constraints, index);
	}
    
public voidaddChangeListener(javax.swing.event.ChangeListener l)
Adds a ChangeListener to this tabbedpane.

param
l the ChangeListener to add
see
#fireStateChanged
see
#removeChangeListener

        listenerList.add(ChangeListener.class, l);
    
public voidaddTab(java.lang.String title, javax.swing.Icon icon, java.awt.Component component, java.lang.String tip)
Adds a component and tip represented by a title and/or icon, either of which can be null. Cover method for insertTab.

param
title the title to be displayed in this tab
param
icon the icon to be displayed in this tab
param
component the component to be displayed when this tab is clicked
param
tip the tooltip to be displayed for this tab
see
#insertTab
see
#removeTabAt

        insertTab(title, icon, component, tip, pages.size()); 
    
public voidaddTab(java.lang.String title, javax.swing.Icon icon, java.awt.Component component)
Adds a component represented by a title and/or icon, either of which can be null. Cover method for insertTab.

param
title the title to be displayed in this tab
param
icon the icon to be displayed in this tab
param
component the component to be displayed when this tab is clicked
see
#insertTab
see
#removeTabAt

        insertTab(title, icon, component, null, pages.size()); 
    
public voidaddTab(java.lang.String title, java.awt.Component component)
Adds a component represented by a title and no icon. Cover method for insertTab.

param
title the title to be displayed in this tab
param
component the component to be displayed when this tab is clicked
see
#insertTab
see
#removeTabAt

        insertTab(title, null, component, null, pages.size()); 
    
private voidcheckIndex(int index)

	if (index < 0 || index >= pages.size()) {
	    throw new IndexOutOfBoundsException("Index: "+index+", Tab count: "+pages.size());
	}
    
voidcompWriteObjectNotify()

        super.compWriteObjectNotify();
        // If ToolTipText != null, then the tooltip has already been
        // unregistered by JComponent.compWriteObjectNotify()
        if (getToolTipText() == null && haveRegistered) {
            ToolTipManager.sharedInstance().unregisterComponent(this);
        }           
    
protected javax.swing.event.ChangeListenercreateChangeListener()
Subclasses that want to handle ChangeEvents differently can override this to return a subclass of ModelListener or another ChangeListener implementation.

see
#fireStateChanged

        return new ModelListener();
    
protected voidfireStateChanged()
Sends a ChangeEvent, whose source is this tabbedpane, to each listener. This method method is called each time a ChangeEvent is received from the model.

see
#addChangeListener
see
EventListenerList

        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ChangeListener.class) {
                // Lazily create the event:
                if (changeEvent == null)
                    changeEvent = new ChangeEvent(this);
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
            }          
        }
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JTabbedPane. For tabbed panes, the AccessibleContext takes the form of an AccessibleJTabbedPane. A new AccessibleJTabbedPane instance is created if necessary.

return
an AccessibleJTabbedPane that serves as the AccessibleContext of this JTabbedPane

        if (accessibleContext == null) {
            accessibleContext = new AccessibleJTabbedPane();
        }
        return accessibleContext;
    
public java.awt.ColorgetBackgroundAt(int index)
Returns the tab background color at index.

param
index the index of the item being queried
return
the Color of the tab background at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setBackgroundAt

        return ((Page)pages.elementAt(index)).getBackground();
    
public java.awt.RectanglegetBoundsAt(int index)
Returns the tab bounds at index. If the tab at this index is not currently visible in the UI, then returns null. If there is no UI set on this tabbedpane, then returns null.

param
index the index to be queried
return
a Rectangle containing the tab bounds at index, or null if tab at index is not currently visible in the UI, or if there is no UI set on this tabbedpane
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)

	checkIndex(index);
        if (ui != null) {
            return ((TabbedPaneUI)ui).getTabBounds(this, index);
        }
        return null;
    
public javax.swing.event.ChangeListener[]getChangeListeners()
Returns an array of all the ChangeListeners added to this JTabbedPane with addChangeListener.

return
all of the ChangeListeners added or an empty array if no listeners have been added
since
1.4

        return (ChangeListener[])listenerList.getListeners(
                ChangeListener.class);
    
public java.awt.ComponentgetComponentAt(int index)
Returns the component at index.

param
index the index of the item being queried
return
the Component at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setComponentAt

        return ((Page)pages.elementAt(index)).component;
    
public javax.swing.IcongetDisabledIconAt(int index)
Returns the tab disabled icon at index. If the tab disabled icon doesn't exist at index this will forward the call to the look and feel to construct an appropriate disabled Icon from the corresponding enabled Icon. Some look and feels might not render the disabled Icon, in which case it won't be created.

param
index the index of the item being queried
return
the icon at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setDisabledIconAt

        Page page = ((Page)pages.elementAt(index));
        if (page.disabledIcon == null) {
            page.disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, page.icon);
        }
        return page.disabledIcon;
    
public intgetDisplayedMnemonicIndexAt(int tabIndex)
Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character.

since
1.4
param
tabIndex the index of the tab that the mnemonic refers to
return
index representing mnemonic character if one exists; otherwise returns -1
exception
IndexOutOfBoundsException if index is out of range (tabIndex < 0 || tabIndex >= tab count)
see
#setDisplayedMnemonicIndexAt(int,int)
see
#setMnemonicAt(int,int)

	checkIndex(tabIndex);

        Page page = (Page)pages.elementAt(tabIndex);
	return page.getDisplayedMnemonicIndex();
    
public java.awt.ColorgetForegroundAt(int index)
Returns the tab foreground color at index.

param
index the index of the item being queried
return
the Color of the tab foreground at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setForegroundAt

        return ((Page)pages.elementAt(index)).getForeground();
    
public javax.swing.IcongetIconAt(int index)
Returns the tab icon at index.

param
index the index of the item being queried
return
the icon at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setIconAt

        return ((Page)pages.elementAt(index)).icon;
    
public intgetMnemonicAt(int tabIndex)
Returns the keyboard mnemonic for accessing the specified tab. The mnemonic is the key which when combined with the look and feel's mouseless modifier (usually Alt) will activate the specified tab.

since
1.4
param
tabIndex the index of the tab that the mnemonic refers to
return
the key code which represents the mnemonic; -1 if a mnemonic is not specified for the tab
exception
IndexOutOfBoundsException if index is out of range (tabIndex < 0 || tabIndex >= tab count)
see
#setDisplayedMnemonicIndexAt(int,int)
see
#setMnemonicAt(int,int)

	checkIndex(tabIndex);

        Page page = (Page)pages.elementAt(tabIndex);
	return page.getMnemonic();
    
public javax.swing.SingleSelectionModelgetModel()
Returns the model associated with this tabbedpane.

see
#setModel

        return model;
    
public java.awt.ComponentgetSelectedComponent()
Returns the currently selected component for this tabbedpane. Returns null if there is no currently selected tab.

return
the component corresponding to the selected tab
see
#setSelectedComponent

 
        int index = getSelectedIndex();
        if (index == -1) {
            return null;
        }
        return getComponentAt(index);
    
public intgetSelectedIndex()
Returns the currently selected index for this tabbedpane. Returns -1 if there is no currently selected tab.

return
the index of the selected tab
see
#setSelectedIndex

        return model.getSelectedIndex();
    
public intgetTabCount()
Returns the number of tabs in this tabbedpane.

return
an integer specifying the number of tabbed pages

        return pages.size();
    
public intgetTabLayoutPolicy()
Returns the policy used by the tabbedpane to layout the tabs when all the tabs will not fit within a single run.

see
#setTabLayoutPolicy
since
1.4

        return tabLayoutPolicy;
    
public intgetTabPlacement()
Returns the placement of the tabs for this tabbedpane.

see
#setTabPlacement

        return tabPlacement;
    
public intgetTabRunCount()
Returns the number of tab runs currently used to display the tabs.

return
an integer giving the number of rows if the tabPlacement is TOP or BOTTOM and the number of columns if tabPlacement is LEFT or RIGHT, or 0 if there is no UI set on this tabbedpane

        if (ui != null) {
            return ((TabbedPaneUI)ui).getTabRunCount(this);
        }
        return 0;
    
public java.lang.StringgetTitleAt(int index)
Returns the tab title at index.

param
index the index of the item being queried
return
the title at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setTitleAt

        return ((Page)pages.elementAt(index)).title;
    
public java.lang.StringgetToolTipText(java.awt.event.MouseEvent event)
Returns the tooltip text for the component determined by the mouse event location.

param
event the MouseEvent that tells where the cursor is lingering
return
the String containing the tooltip text

        if (ui != null) {
            int index = ((TabbedPaneUI)ui).tabForCoordinate(this, event.getX(), event.getY());

            if (index != -1) {
                return ((Page)pages.elementAt(index)).tip;
            }
        }
        return super.getToolTipText(event);
    
public java.lang.StringgetToolTipTextAt(int index)
Returns the tab tooltip text at index.

param
index the index of the item being queried
return
a string containing the tool tip text at index
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setToolTipTextAt

        return ((Page)pages.elementAt(index)).tip;
    
public javax.swing.plaf.TabbedPaneUIgetUI()
Returns the UI object which implements the L&F for this component.

return
a TabbedPaneUI object
see
#setUI

        return (TabbedPaneUI)ui;
    
public java.lang.StringgetUIClassID()
Returns the name of the UI class that implements the L&F for this component.

return
the string "TabbedPaneUI"
see
JComponent#getUIClassID
see
UIDefaults#getUI

        return uiClassID;
    
public intindexAtLocation(int x, int y)
Returns the tab index corresponding to the tab whose bounds intersect the specified location. Returns -1 if no tab intersects the location.

param
x the x location relative to this tabbedpane
param
y the y location relative to this tabbedpane
return
the tab index which intersects the location, or -1 if no tab intersects the location
since
1.4

        if (ui != null) {
            return ((TabbedPaneUI)ui).tabForCoordinate(this, x, y);
        }
        return -1;
    
public intindexOfComponent(java.awt.Component component)
Returns the index of the tab for the specified component. Returns -1 if there is no tab for this component.

param
component the component for the tab
return
the first tab which matches this component, or -1 if there is no tab for this component

        for(int i = 0; i < getTabCount(); i++) {
            Component c = getComponentAt(i);
            if ((c != null && c.equals(component)) ||
                (c == null && c == component)) { 
                return i;
            }
        }
        return -1; 
    
public intindexOfTab(java.lang.String title)
Returns the first tab index with a given title, or -1 if no tab has this title.

param
title the title for the tab
return
the first tab index which matches title, or -1 if no tab has this title

        for(int i = 0; i < getTabCount(); i++) { 
            if (getTitleAt(i).equals(title == null? "" : title)) { 
                return i;
            }
        }
        return -1; 
    
public intindexOfTab(javax.swing.Icon icon)
Returns the first tab index with a given icon, or -1 if no tab has this icon.

param
icon the icon for the tab
return
the first tab index which matches icon, or -1 if no tab has this icon

        for(int i = 0; i < getTabCount(); i++) {
            Icon tabIcon = getIconAt(i);
            if ((tabIcon != null && tabIcon.equals(icon)) ||
                (tabIcon == null && tabIcon == icon)) { 
                return i;
            }
        }
        return -1; 
    
public voidinsertTab(java.lang.String title, javax.swing.Icon icon, java.awt.Component component, java.lang.String tip, int index)
Inserts a component, at index, represented by a title and/or icon, either of which may be null. Uses java.util.Vector internally, see insertElementAt for details of insertion conventions.

param
title the title to be displayed in this tab
param
icon the icon to be displayed in this tab
param
component The component to be displayed when this tab is clicked.
param
tip the tooltip to be displayed for this tab
param
index the position to insert this new tab
see
#addTab
see
#removeTabAt

	int newIndex = index;

        // If component already exists, remove corresponding
        // tab so that new tab gets added correctly
        // Note: we are allowing component=null because of compatibility,
        // but we really should throw an exception because much of the
        // rest of the JTabbedPane implementation isn't designed to deal
        // with null components for tabs.
        int removeIndex = indexOfComponent(component);
        if (component != null && removeIndex != -1) {
            removeTabAt(removeIndex);
	    if (newIndex > removeIndex) {
		newIndex--;
	    }
        }

        int selectedIndex = getSelectedIndex();

        pages.insertElementAt(new Page(this, title != null? title : "", icon, null,
                                       component, tip), newIndex);


        if (component != null) {
            addImpl(component, null, -1);
            component.setVisible(false);
        }

        if (pages.size() == 1) {
            setSelectedIndex(0);
        }

        if (selectedIndex >= newIndex) {
            setSelectedIndex(selectedIndex + 1);
        }

        if (!haveRegistered && tip != null) {
            ToolTipManager.sharedInstance().registerComponent(this);
            haveRegistered = true;
        }

        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 
                    null, component);
        }
        revalidate();
        repaint();
    
public booleanisEnabledAt(int index)
Returns whether or not the tab at index is currently enabled.

param
index the index of the item being queried
return
true if the tab at index is enabled; false otherwise
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setEnabledAt

        return ((Page)pages.elementAt(index)).isEnabled();
    
protected java.lang.StringparamString()
Returns a string representation of this JTabbedPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

return
a string representation of this JTabbedPane.

        String tabPlacementString;
        if (tabPlacement == TOP) {
            tabPlacementString = "TOP";
        } else if (tabPlacement == BOTTOM) {
            tabPlacementString = "BOTTOM";
        } else if (tabPlacement == LEFT) {
            tabPlacementString = "LEFT";
        } else if (tabPlacement == RIGHT) {
            tabPlacementString = "RIGHT";
        } else tabPlacementString = "";
        String haveRegisteredString = (haveRegistered ?
				       "true" : "false");

	return super.paramString() +
        ",haveRegistered=" + haveRegisteredString +
        ",tabPlacement=" + tabPlacementString;
    
private voidreadObject(java.io.ObjectInputStream s)
See readObject and writeObject in JComponent for more information about serialization in Swing.

        s.defaultReadObject();
	if ((ui != null) && (getUIClassID().equals(uiClassID))) {
	    ui.installUI(this);
	}
        // If ToolTipText != null, then the tooltip has already been
        // registered by JComponent.readObject() 
        if (getToolTipText() == null && haveRegistered) {
            ToolTipManager.sharedInstance().registerComponent(this);
        }
    
public voidremove(java.awt.Component component)
Removes the specified Component from the JTabbedPane. The method does nothing if the component is null.

param
component the component to remove from the tabbedpane
see
#addTab
see
#removeTabAt

        int index = indexOfComponent(component);
        if (index != -1) {
            removeTabAt(index);
        } else {
	    // Container#remove(comp) invokes Container#remove(int)
	    // so make sure JTabbedPane#remove(int) isn't called here
	    Component children[] = getComponents();
	    for (int i=0; i < children.length; i++) {
		if (component == children[i]) {
		    super.remove(i);
		    break;
		}
	    }
        }
    
public voidremove(int index)
Removes the tab and component which corresponds to the specified index.

param
index the index of the component to remove from the tabbedpane
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#addTab
see
#removeTabAt

        removeTabAt(index);
    
public voidremoveAll()
Removes all the tabs and their corresponding components from the tabbedpane.

see
#addTab
see
#removeTabAt

        setSelectedIndexImpl(-1);

        int tabCount = getTabCount();
        // We invoke removeTabAt for each tab, otherwise we may end up
        // removing Components added by the UI.
        while (tabCount-- > 0) {
            removeTabAt(tabCount);
        }
    
public voidremoveChangeListener(javax.swing.event.ChangeListener l)
Removes a ChangeListener from this tabbedpane.

param
l the ChangeListener to remove
see
#fireStateChanged
see
#addChangeListener

        listenerList.remove(ChangeListener.class, l);
    
public voidremoveTabAt(int index)
Removes the tab at index. After the component associated with index is removed, its visibility is reset to true to ensure it will be visible if added to other containers.

param
index the index of the tab to be removed
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#addTab
see
#insertTab

    
        checkIndex(index);

        // If we are removing the currently selected tab AND
        // it happens to be the last tab in the bunch, then
        // select the previous tab
        int tabCount = getTabCount();
        int selected = getSelectedIndex();
        if (selected >= (tabCount - 1)) {
            setSelectedIndexImpl(selected - 1);
        }

        Component component = getComponentAt(index);

        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 
                    component, null);
        }

        pages.removeElementAt(index);

        // NOTE 4/15/2002 (joutwate):
        // This fix is implemented using client properties since there is
        // currently no IndexPropertyChangeEvent.  Once
        // IndexPropertyChangeEvents have been added this code should be
        // modified to use it.
        putClientProperty("__index_to_remove__", new Integer(index));

        // We can't assume the tab indices correspond to the 
        // container's children array indices, so make sure we
        // remove the correct child!
        if (component != null) {
	    Component components[] = getComponents();
	    for (int i = components.length; --i >= 0; ) {
		if (components[i] == component) {
                    super.remove(i);
                    component.setVisible(true);
                    break;
		}
	    }
        }

        revalidate();
        repaint();
    
public voidsetBackgroundAt(int index, java.awt.Color background)
Sets the background color at index to background which can be null, in which case the tab's background color will default to the background color of the tabbedpane. An internal exception is raised if there is no tab at that index.

param
index the tab index where the background should be set
param
background the color to be displayed in the tab's background
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getBackgroundAt
beaninfo
preferred: true attribute: visualUpdate true description: The background color at the specified tab index.

        Color oldBg = ((Page)pages.elementAt(index)).background;
        ((Page)pages.elementAt(index)).setBackground(background);
        if (background == null || oldBg == null ||
            !background.equals(oldBg)) {
            Rectangle tabBounds = getBoundsAt(index);
            if (tabBounds != null) {
                repaint(tabBounds);
            }
        }
    
public voidsetComponentAt(int index, java.awt.Component component)
Sets the component at index to component. An internal exception is raised if there is no tab at that index.

param
index the tab index where this component is being placed
param
component the component for the tab
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getComponentAt
beaninfo
attribute: visualUpdate true description: The component at the specified tab index.

        Page page = (Page)pages.elementAt(index);
        if (component != page.component) {
            if (page.component != null) {
                // REMIND(aim): this is really silly;
                // why not if (page.component.getParent() == this) remove(component)
                synchronized(getTreeLock()) {
                    int count = getComponentCount();
                    Component children[] = getComponents();
                    for (int i = 0; i < count; i++) {
                        if (children[i] == page.component) {
                            super.remove(i);
                        }
                    }
                }
            }
            page.component = component;
            component.setVisible(getSelectedIndex() == index);
            addImpl(component, null, -1);
            
            revalidate();
        }
    
public voidsetDisabledIconAt(int index, javax.swing.Icon disabledIcon)
Sets the disabled icon at index to icon which can be null. An internal exception is raised if there is no tab at that index.

param
index the tab index where the disabled icon should be set
param
disabledIcon the icon to be displayed in the tab when disabled
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getDisabledIconAt
beaninfo
preferred: true attribute: visualUpdate true description: The disabled icon at the specified tab index.

        Icon oldIcon = ((Page)pages.elementAt(index)).disabledIcon;
        ((Page)pages.elementAt(index)).disabledIcon = disabledIcon;
        if (disabledIcon != oldIcon && !isEnabledAt(index)) {
            revalidate();
            repaint();
        }
    
public voidsetDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex)
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. Not all look and feels may support this. A value of -1 indicates either there is no mnemonic for this tab, or you do not wish the mnemonic to be displayed for this tab.

The value of this is updated as the properties relating to the mnemonic change (such as the mnemonic itself, the text...). You should only ever have to call this if you do not wish the default character to be underlined. For example, if the text at tab index 3 was 'Apple Price', with a mnemonic of 'p', and you wanted the 'P' to be decorated, as 'Apple Price', you would have to invoke setDisplayedMnemonicIndex(3, 6) after invoking setMnemonicAt(3, KeyEvent.VK_P).

Note that it is the programmer's responsibility to ensure that each tab has a unique mnemonic or unpredictable results may occur.

since
1.4
param
tabIndex the index of the tab that the mnemonic refers to
param
mnemonicIndex index into the String to underline
exception
IndexOutOfBoundsException if tabIndex is out of range (tabIndex < 0 || tabIndex >= tab count)
exception
IllegalArgumentException will be thrown if mnemonicIndex is >= length of the tab title , or < -1
see
#setMnemonicAt(int,int)
see
#getDisplayedMnemonicIndexAt(int)
beaninfo
bound: true attribute: visualUpdate true description: the index into the String to draw the keyboard character mnemonic at

	checkIndex(tabIndex);

        Page page = (Page)pages.elementAt(tabIndex);

        page.setDisplayedMnemonicIndex(mnemonicIndex);
    
public voidsetEnabledAt(int index, boolean enabled)
Sets whether or not the tab at index is enabled. An internal exception is raised if there is no tab at that index.

param
index the tab index which should be enabled/disabled
param
enabled whether or not the tab should be enabled
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#isEnabledAt

        boolean oldEnabled = ((Page)pages.elementAt(index)).isEnabled();
        ((Page)pages.elementAt(index)).setEnabled(enabled);
        if (enabled != oldEnabled) {
            revalidate();
            repaint();
        }
    
public voidsetForegroundAt(int index, java.awt.Color foreground)
Sets the foreground color at index to foreground which can be null, in which case the tab's foreground color will default to the foreground color of this tabbedpane. An internal exception is raised if there is no tab at that index.

param
index the tab index where the foreground should be set
param
foreground the color to be displayed as the tab's foreground
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getForegroundAt
beaninfo
preferred: true attribute: visualUpdate true description: The foreground color at the specified tab index.

        Color oldFg = ((Page)pages.elementAt(index)).foreground;
        ((Page)pages.elementAt(index)).setForeground(foreground);
        if (foreground == null || oldFg == null ||
            !foreground.equals(oldFg)) {
            Rectangle tabBounds = getBoundsAt(index);
            if (tabBounds != null) {
                repaint(tabBounds);
            }
        }
    
public voidsetIconAt(int index, javax.swing.Icon icon)
Sets the icon at index to icon which can be null. This does not set disabled icon at icon. If the new Icon is different than the current Icon and disabled icon is not explicitly set, the LookAndFeel will be asked to generate a disabled Icon. To explicitly set disabled icon, use setDisableIconAt(). An internal exception is raised if there is no tab at that index.

param
index the tab index where the icon should be set
param
icon the icon to be displayed in the tab
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#setDisabledIconAt
see
#getIconAt
see
#getDisabledIconAt
beaninfo
preferred: true attribute: visualUpdate true description: The icon at the specified tab index.

        Page page = (Page)pages.elementAt(index);
        Icon oldIcon = page.icon;        
        if (icon != oldIcon) {
            page.icon = icon;
    
            /* If the default icon has really changed and we had
             * generated the disabled icon for this page, then
             * clear the disabledIcon field of the page.
             */
            if (page.disabledIcon instanceof UIResource) {
                page.disabledIcon = null;
            }
    
            // Fire the accessibility Visible data change
            if (accessibleContext != null) {
                accessibleContext.firePropertyChange(
                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 
                        oldIcon, icon);
            }
            revalidate();
            repaint();
        }
    
public voidsetMnemonicAt(int tabIndex, int mnemonic)
Sets the keyboard mnemonic for accessing the specified tab. The mnemonic is the key which when combined with the look and feel's mouseless modifier (usually Alt) will activate the specified tab.

A mnemonic must correspond to a single key on the keyboard and should be specified using one of the VK_XXX keycodes defined in java.awt.event.KeyEvent. Mnemonics are case-insensitive, therefore a key event with the corresponding keycode would cause the button to be activated whether or not the Shift modifier was pressed.

This will update the displayed mnemonic property for the specified tab.

since
1.4
param
tabIndex the index of the tab that the mnemonic refers to
param
mnemonic the key code which represents the mnemonic
exception
IndexOutOfBoundsException if tabIndex is out of range (tabIndex < 0 || tabIndex >= tab count)
see
#getMnemonicAt(int)
see
#setDisplayedMnemonicIndexAt(int,int)
beaninfo
bound: true attribute: visualUpdate true description: The keyboard mnenmonic, as a KeyEvent VK constant, for the specified tab

	checkIndex(tabIndex);

        Page page = (Page)pages.elementAt(tabIndex);
	page.setMnemonic(mnemonic);

        firePropertyChange("mnemonicAt", null, null);
    
public voidsetModel(javax.swing.SingleSelectionModel model)
Sets the model to be used with this tabbedpane.

param
model the model to be used
see
#getModel
beaninfo
bound: true description: The tabbedpane's SingleSelectionModel.

        SingleSelectionModel oldModel = getModel();

        if (oldModel != null) {
            oldModel.removeChangeListener(changeListener);
            changeListener = null;
        }

        this.model = model;

        if (model != null) {
            changeListener = createChangeListener();
            model.addChangeListener(changeListener);
        }

        firePropertyChange("model", oldModel, model);
        repaint();
    
public voidsetSelectedComponent(java.awt.Component c)
Sets the selected component for this tabbedpane. This will automatically set the selectedIndex to the index corresponding to the specified component.

exception
IllegalArgumentException if component not found in tabbed pane
see
#getSelectedComponent
beaninfo
preferred: true description: The tabbedpane's selected component.

        int index = indexOfComponent(c);
        if (index != -1) {
            setSelectedIndex(index);
        } else {
            throw new IllegalArgumentException("component not found in tabbed pane");
        }
    
public voidsetSelectedIndex(int index)
Sets the selected index for this tabbedpane. The index must be a valid tab index or -1, which indicates that no tab should be selected (can also be used when there are no tabs in the tabbedpane). If a -1 value is specified when the tabbedpane contains one or more tabs, then the results will be implementation defined.

param
index the index to be selected
exception
IndexOutOfBoundsException if index is out of range (index < -1 || index >= tab count)
see
#getSelectedIndex
see
SingleSelectionModel#setSelectedIndex
beaninfo
preferred: true description: The tabbedpane's selected tab index.

	if (index != -1) {
	    checkIndex(index);
	}
	setSelectedIndexImpl(index);
    
private voidsetSelectedIndexImpl(int index)

        int oldIndex = model.getSelectedIndex();
        Page oldPage = null, newPage = null;
        if ((oldIndex >= 0) && (oldIndex != index)) {
            oldPage = (Page) pages.elementAt(oldIndex);
        }
        if ((index >= 0) && (oldIndex != index)) {
            newPage = (Page) pages.elementAt(index);
        }

        model.setSelectedIndex(index);

        String oldName = null;
        String newName = null;

        if (oldPage != null) {
            oldPage.firePropertyChange(
                AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 
                AccessibleState.SELECTED, null);
            // TIGER - 4840667
            AccessibleContext ac = oldPage.getAccessibleContext();
            if (ac != null) {
                oldName = ac.getAccessibleName();
            }

        }
        if (newPage != null) {
            newPage.firePropertyChange(
                AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                null, AccessibleState.SELECTED);
            // TIGER - 4840667
            AccessibleContext ac = newPage.getAccessibleContext();
            if (ac != null) {
                newName = ac.getAccessibleName();
            }

        }

        // TIGER - 4840667
        if (newName != null) {
            getAccessibleContext().firePropertyChange(
                AccessibleContext.ACCESSIBLE_NAME_PROPERTY, oldName, newName);
        }

    
public voidsetTabLayoutPolicy(int tabLayoutPolicy)
Sets the policy which the tabbedpane will use in laying out the tabs when all the tabs will not fit within a single run. Possible values are:
  • JTabbedPane.WRAP_TAB_LAYOUT
  • JTabbedPane.SCROLL_TAB_LAYOUT
The default value, if not set by the UI, is JTabbedPane.WRAP_TAB_LAYOUT.

Some look and feels might only support a subset of the possible layout policies, in which case the value of this property may be ignored.

param
tabLayoutPolicy the policy used to layout the tabs
exception
IllegalArgumentException if layoutPolicy value isn't one of the above valid values
see
#getTabLayoutPolicy
since
1.4
beaninfo
preferred: true bound: true attribute: visualUpdate true enum: WRAP_TAB_LAYOUT JTabbedPane.WRAP_TAB_LAYOUT SCROLL_TAB_LAYOUT JTabbedPane.SCROLL_TAB_LAYOUT description: The tabbedpane's policy for laying out the tabs

        if (tabLayoutPolicy != WRAP_TAB_LAYOUT && tabLayoutPolicy != SCROLL_TAB_LAYOUT) {
            throw new IllegalArgumentException("illegal tab layout policy: must be WRAP_TAB_LAYOUT or SCROLL_TAB_LAYOUT");
        }
        if (this.tabLayoutPolicy != tabLayoutPolicy) {
            int oldValue = this.tabLayoutPolicy;
            this.tabLayoutPolicy = tabLayoutPolicy;
            firePropertyChange("tabLayoutPolicy", oldValue, tabLayoutPolicy);
            revalidate();
            repaint();
        }
    
public voidsetTabPlacement(int tabPlacement)
Sets the tab placement for this tabbedpane. Possible values are:
  • JTabbedPane.TOP
  • JTabbedPane.BOTTOM
  • JTabbedPane.LEFT
  • JTabbedPane.RIGHT
The default value, if not set, is SwingConstants.TOP.

param
tabPlacement the placement for the tabs relative to the content
exception
IllegalArgumentException if tab placement value isn't one of the above valid values
beaninfo
preferred: true bound: true attribute: visualUpdate true enum: TOP JTabbedPane.TOP LEFT JTabbedPane.LEFT BOTTOM JTabbedPane.BOTTOM RIGHT JTabbedPane.RIGHT description: The tabbedpane's tab placement.

        if (tabPlacement != TOP && tabPlacement != LEFT && 
            tabPlacement != BOTTOM && tabPlacement != RIGHT) {
            throw new IllegalArgumentException("illegal tab placement: must be TOP, BOTTOM, LEFT, or RIGHT");
        }
        if (this.tabPlacement != tabPlacement) {
            int oldValue = this.tabPlacement;
            this.tabPlacement = tabPlacement;
            firePropertyChange("tabPlacement", oldValue, tabPlacement);
            revalidate();
            repaint();
        }
    
public voidsetTitleAt(int index, java.lang.String title)
Sets the title at index to title which can be null. An internal exception is raised if there is no tab at that index.

param
index the tab index where the title should be set
param
title the title to be displayed in the tab
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getTitleAt
beaninfo
preferred: true attribute: visualUpdate true description: The title at the specified tab index.

        Page page = (Page)pages.elementAt(index);
        String oldTitle =page.title;
        page.title = title;
        
	if (oldTitle != title) {
	    firePropertyChange("indexForTitle", -1, index);
	}
        page.updateDisplayedMnemonicIndex();
        if ((oldTitle != title) && (accessibleContext != null)) {
            accessibleContext.firePropertyChange(
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 
                    oldTitle, title);
        }
        if (title == null || oldTitle == null ||
            !title.equals(oldTitle)) {
            revalidate();
            repaint();
        }
    
public voidsetToolTipTextAt(int index, java.lang.String toolTipText)
Sets the tooltip text at index to toolTipText which can be null. An internal exception is raised if there is no tab at that index.

param
index the tab index where the tooltip text should be set
param
toolTipText the tooltip text to be displayed for the tab
exception
IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
see
#getToolTipTextAt
beaninfo
preferred: true description: The tooltip text at the specified tab index.

        String oldToolTipText =((Page)pages.elementAt(index)).tip;
        ((Page)pages.elementAt(index)).tip = toolTipText;

        if ((oldToolTipText != toolTipText) && (accessibleContext != null)) {
            accessibleContext.firePropertyChange(
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 
                    oldToolTipText, toolTipText);
        }
        if (!haveRegistered && toolTipText != null) {
            ToolTipManager.sharedInstance().registerComponent(this);
            haveRegistered = true;
        }
    
public voidsetUI(javax.swing.plaf.TabbedPaneUI ui)
Sets the UI object which implements the L&F for this component.

param
ui the new UI object
see
UIDefaults#getUI
beaninfo
bound: true hidden: true attribute: visualUpdate true description: The UI object that implements the tabbedpane's LookAndFeel

        super.setUI(ui);
        // disabled icons are generated by LF so they should be unset here
        for (int i = 0; i < getTabCount(); i++) {
            Icon icon = ((Page)pages.elementAt(i)).disabledIcon;
            if (icon instanceof UIResource) {
                setDisabledIconAt(i, null);
            }
        }
    
public voidupdateUI()
Resets the UI property to a value from the current look and feel.

see
JComponent#updateUI

        setUI((TabbedPaneUI)UIManager.getUI(this));
    
private voidwriteObject(java.io.ObjectOutputStream s)
See readObject and writeObject in JComponent for more information about serialization in Swing.

        s.defaultWriteObject();
        if (getUIClassID().equals(uiClassID)) {
            byte count = JComponent.getWriteObjCounter(this);
            JComponent.setWriteObjCounter(this, --count);
            if (count == 0 && ui != null) {
                ui.installUI(this);
            }
        }