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.
The tab title can be rendered by a Component.
For example, the following produce similar results:
// In this case the look and feel renders the title for the tab.
tabbedPane.addTab("Tab", myComponent);
// In this case the custom component is responsible for rendering the
// title of the tab.
tabbedPane.addTab(null, myComponent);
tabbedPane.setTabComponentAt(0, new JLabel("Tab"));
The latter is typically used when you want a more complex user interaction
that requires custom components on the tab. For example, you could
provide a custom component that animates or one that has widgets for
closing the tab.
If you specify a component for a tab, the JTabbedPane
will not render any text or icon you have specified for the tab.
Note
Do not use setVisible directly on a tab component to make it visible,
use setSelectedComponent or setSelectedIndex methods instead.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
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 JavaBeans
has been added to the java.beans package.
Please see java..
SingleSelectionModel
| Modifier and Type | Class and Description |
|---|---|
| protected class | JTabbedPane.
This class implements accessibility support for the
|
| protected class | JTabbedPane.
We pass |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| protected transient ChangeEvent | changeEvent
Only one |
| protected ChangeListener | changeListener
The |
| private boolean | |
| protected SingleSelectionModel | model
The default selection model |
| private List | |
| 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. |
| private int | |
| protected int | tabPlacement
Where the tabs are placed. |
| private static final String | |
| private Component | |
| 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. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JTabbedPane(int
the placement for the tabs relative to the content tabPlacement)Creates an empty |
| public | JTabbedPane(int
the placement for the tabs relative to the content tabPlacement, int the policy for laying out tabs when all tabs will not fit on one run tabLayoutPolicy)Creates an empty |
| Modifier and Type | Method and Description |
|---|---|
| public Component | Returns: the componentthe component to be displayed when this tab is clicked component)Overrides java. Adds a |
| public Component | Returns: the componentthe title to be displayed in this tab title, Component the component to be displayed when this tab is clicked component)Overrides java. Adds a |
| public Component | Returns: the componentthe component to be displayed when this tab is clicked component, int the position to insert this new tab index)Overrides java. Adds a |
| public void | add(Component
the component to be displayed when this tab is clicked component, Object the object to be displayed in the tab constraints)Overrides java. Adds a |
| public void | add(Component
the component to be displayed when this tab is clicked component, Object the object to be displayed in the tab constraints, int the position to insert this new tab index)Overrides java. Adds a |
| public void | addChangeListener(ChangeListener
the l)ChangeListener to addAdds a |
| public void | addTab(String
the title to be displayed in this tab title, Icon the icon to be displayed in this tab icon, Component the component to be displayed when this tab is clicked component, String the tooltip to be displayed for this tab tip)Adds a |
| public void | |
| public void | |
| private void | |
| private void | |
| private static void | |
| private static void | |
| private void | |
| pack-priv void | compWriteObjectNotify()
Overrides javax. This is called from Component by way of reflection. |
| protected ChangeListener | Returns: aChangeListenerSubclasses that want to handle |
| protected void | fireStateChanged()
Sends a |
| public AccessibleContext | Returns: an AccessibleJTabbedPane that serves as the AccessibleContext of this JTabbedPaneOverrides java. Implements javax. Gets the AccessibleContext associated with this JTabbedPane. |
| public Color | Returns: theColor of the tab background at
indexthe index of the item being queried index)Returns the tab background color at |
| public Rectangle | Returns: aRectangle 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 tabbedpanethe index to be queried index)Returns the tab bounds at |
| public ChangeListener[] | Returns: all of theChangeListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public Component | Returns: theComponent at indexthe index of the item being queried index)Returns the component at |
| public Icon | Returns: the icon atindexthe index of the item being queried index)Returns the tab disabled icon at |
| public int | Returns: index representing mnemonic character if one exists; otherwise returns -1the index of the tab that the mnemonic refers to tabIndex)Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character. |
| public Color | Returns: theColor of the tab foreground at
indexthe index of the item being queried index)Returns the tab foreground color at |
| public Icon | Returns: the icon atindexthe index of the item being queried index)Returns the tab icon at |
| public int | Returns: the key code which represents the mnemonic; -1 if a mnemonic is not specified for the tabthe index of the tab that the mnemonic refers to tabIndex)Returns the keyboard mnemonic for accessing the specified tab. |
| public SingleSelectionModel | Returns: theSingleSelectionModel associated with this tabbedpaneReturns the model associated with this tabbedpane. |
| public Component | Returns: the component corresponding to the selected tabReturns the currently selected component for this tabbedpane. |
| public int | Returns: the index of the selected tabReturns the currently selected index for this tabbedpane. |
| public Component | Returns: the tab component atindexthe index of the item being queried index)Returns the tab component at |
| public int | Returns: an integer specifying the number of tabbed pagesReturns the number of tabs in this |
| public int | Returns: anint specifying the policy used to layout the tabsReturns the policy used by the tabbedpane to layout the tabs when all the tabs will not fit within a single run. |
| public int | Returns: anint specifying the placement for the tabsReturns the placement of the tabs for this tabbedpane. |
| public int | Returns: an integer giving the number of rows if thetabPlacement
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 tabbedpaneReturns the number of tab runs currently used to display the tabs. |
| public String | Returns: the title atindexthe index of the item being queried index)Returns the tab title at |
| public String | Returns: theString containing the tooltip textthe event)MouseEvent that tells where the
cursor is lingeringOverrides javax. Returns the tooltip text for the component determined by the mouse event location. |
| public String | Returns: a string containing the tool tip text atindexthe index of the item being queried index)Returns the tab tooltip text at |
| public TabbedPaneUI | Returns: aTabbedPaneUI objectOverrides javax. Returns the UI object which implements the L&F for this component. |
| public String | Returns: the string "TabbedPaneUI"Overrides javax. Returns the name of the UI class that implements the L&F for this component. |
| public int | Returns: the tab index which intersects the location, or -1 if no tab intersects the locationthe x location relative to this tabbedpane x, int the y location relative to this tabbedpane y)Returns the tab index corresponding to the tab whose bounds intersect the specified location. |
| public int | Returns: the first tab which matches this component, or -1 if there is no tab for this componentthe component for the tab component)Returns the index of the tab for the specified component. |
| public int | Returns: the first tab index which matchestitle, or
-1 if no tab has this titlethe title for the tab title)Returns the first tab index with a given |
| public int | Returns: the first tab index which matchesicon,
or -1 if no tab has this iconthe icon for the tab icon)Returns the first tab index with a given |
| public int | Returns: the first tab which matches this tab component, or -1 if there is no tab for this tab componentthe tab component for the tab tabComponent)Returns the index of the tab for the specified tab component. |
| public void | insertTab(String
the title to be displayed on the tab title, Icon the icon to be displayed on the tab icon, Component the component to be displayed when this tab is clicked. component, String the tooltip to be displayed for this tab tip, int the position to insert this new tab
index)(index >= 0 && index <= getTabCount())Inserts a new tab for the given component, at the given index,
represented by the given title and/or icon, either of which may
be |
| public boolean | Returns: true if the tab atindex is enabled;
false otherwisethe index of the item being queried index)Returns whether or not the tab at |
| protected String | Returns: a string representation of this JTabbedPane.Overrides javax. Returns a string representation of this |
| private void | readObject(ObjectInputStream s)
Hides javax. See |
| public void | remove(Component
the component to remove from the tabbedpane component)Overrides java. Removes the specified |
| public void | remove(int
the index of the component to remove from the
index)tabbedpaneOverrides java. Removes the tab and component which corresponds to the specified index. |
| public void | removeAll()
Overrides java. Removes all the tabs and their corresponding components
from the |
| public void | removeChangeListener(ChangeListener
the l)ChangeListener to removeRemoves a |
| public void | |
| public void | setBackgroundAt(int
the tab index where the background should be set index, Color the color to be displayed in the tab's background background)Sets the background color at |
| public void | setComponentAt(int
the tab index where this component is being placed index, Component the component for the tab component)Sets the component at |
| public void | setDisabledIconAt(int
the tab index where the disabled icon should be set index, Icon the icon to be displayed in the tab when disabled disabledIcon)Sets the disabled icon at |
| public void | setDisplayedMnemonicIndexAt(int
the index of the tab that the mnemonic refers to tabIndex, int index into the mnemonicIndex)String to underlineProvides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. |
| public void | setEnabledAt(int
the tab index which should be enabled/disabled index, boolean whether or not the tab should be enabled enabled)Sets whether or not the tab at |
| public void | setForegroundAt(int
the tab index where the foreground should be set index, Color the color to be displayed as the tab's foreground foreground)Sets the foreground color at |
| public void | |
| public void | setMnemonicAt(int
the index of the tab that the mnemonic refers to tabIndex, int the key code which represents the mnemonic mnemonic)Sets the keyboard mnemonic for accessing the specified tab. |
| public void | setModel(SingleSelectionModel
the model to be used model)Sets the model to be used with this tabbedpane. |
| public void | setSelectedComponent(Component
the selected c)Component for this TabbedPaneSets the selected component for this tabbedpane. |
| public void | |
| private void | |
| public void | setTabComponentAt(int
the tab index where the component should be set index, Component the component to render the title for the
specified tab component)Sets the component that is responsible for rendering the title for the specified tab. |
| public void | setTabLayoutPolicy(int
the policy used to layout the tabs 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. |
| public void | setTabPlacement(int
the placement for the tabs relative to the content tabPlacement)Sets the tab placement for this tabbedpane. |
| public void | setTitleAt(int
the tab index where the title should be set index, String the title to be displayed in the tab title)Sets the title at |
| public void | setToolTipTextAt(int
the tab index where the tooltip text should be set index, String the tooltip text to be displayed for the tab toolTipText)Sets the tooltip text at |
| public void | setUI(TabbedPaneUI
the new UI object ui)Sets the UI object which implements the L&F for this component. |
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |