javax.swing
public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants
Tabs can be oriented in several ways. They can be above, below, left and right of the component. Tabs can either wrap around (by creating multiple rows of tabs) or they can be scrolled (where only a subset of the tabs can be seen at once). More tabs can be added by calling the add/addTab/insertTab methods.
Modifier and Type | Class and Description |
---|---|
protected class |
JTabbedPane.AccessibleJTabbedPane
Accessibility support for
JTabbedPane . |
protected class |
JTabbedPane.ModelListener
A helper class that listens for changes to the model.
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected ChangeEvent |
changeEvent
The changeEvent used to fire changes to listeners.
|
protected ChangeListener |
changeListener
The listener that listens to the model.
|
protected SingleSelectionModel |
model
The model that describes this JTabbedPane.
|
static int |
SCROLL_TAB_LAYOUT
Indicates that the TabbedPane is in scrolling mode.
|
protected int |
tabPlacement
The current tabPlacement of the TabbedPane.
|
static int |
WRAP_TAB_LAYOUT
Indicates that the TabbedPane is in wrap mode.
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JTabbedPane()
Creates a new JTabbedPane object with tabs on top and using wrap tab
layout.
|
JTabbedPane(int tabPlacement)
Creates a new JTabbedPane object using wrap tab layout and the given
tabPlacement , where tabPlacement can be one
of the following values: SwingConstants.TOP , SwingConstants.BOTTOM , SwingConstants.LEFT or
SwingConstants.RIGHT . |
JTabbedPane(int tabPlacement,
int tabLayoutPolicy)
Creates a new JTabbedPane object with the given
tabPlacement
and tabLayoutPolicy . |
Modifier and Type | Method and Description |
---|---|
Component |
add(Component component)
This method adds a tab to the JTabbedPane.
|
Component |
add(Component component,
int index)
This method adds a tab to the JTabbedPane.
|
void |
add(Component component,
Object constraints)
This method adds a tab to the JTabbedPane.
|
void |
add(Component component,
Object constraints,
int index)
This method adds a tab to the JTabbedPane.
|
Component |
add(String title,
Component component)
This method adds a tab to the JTabbedPane.
|
void |
addChangeListener(ChangeListener l)
This method adds a ChangeListener to the JTabbedPane.
|
void |
addTab(String title,
Component component)
This method adds a tab to the JTabbedPane.
|
void |
addTab(String title,
Icon icon,
Component component)
This method adds a tab to the JTabbedPane.
|
void |
addTab(String title,
Icon icon,
Component component,
String tip)
This method adds a tab to the JTabbedPane.
|
protected ChangeListener |
createChangeListener()
This method creates a ChangeListener that is used to listen to the model
for events.
|
protected void |
fireStateChanged()
This method fires a ChangeEvent to all the JTabbedPane's ChangeListeners.
|
AccessibleContext |
getAccessibleContext()
Returns the object that provides accessibility features for this
JTabbedPane component. |
Color |
getBackgroundAt(int index)
This method returns the background color for the tab.
|
Rectangle |
getBoundsAt(int index)
This method returns the bounds of the tab given the index.
|
ChangeListener[] |
getChangeListeners()
This method returns all ChangeListeners registered with the JTabbedPane.
|
Component |
getComponentAt(int index)
This method returns the component associated with the tab.
|
Icon |
getDisabledIconAt(int index)
This method returns the disabled icon given the index.
|
int |
getDisplayedMnemonicIndexAt(int tabIndex)
This method returns the mnemonic index for the tab.
|
Color |
getForegroundAt(int index)
This method returns the foreground color for the tab.
|
Icon |
getIconAt(int index)
This method returns the active icon given the index.
|
int |
getMnemonicAt(int tabIndex)
This method returns the mnemonic for the tab.
|
SingleSelectionModel |
getModel()
This method returns the model used with the JTabbedPane.
|
Component |
getSelectedComponent()
This method returns the component at the selected index.
|
int |
getSelectedIndex()
This method returns the index of the tab that is currently selected.
|
int |
getTabCount()
This method returns how many tabs are in the JTabbedPane.
|
int |
getTabLayoutPolicy()
This method returns the tabLayoutPolicy.
|
int |
getTabPlacement()
This method returns the tabPlacement.
|
int |
getTabRunCount()
This method returns the number of runs used to paint the JTabbedPane.
|
String |
getTitleAt(int index)
This method returns the tab title given the index.
|
String |
getToolTipText(MouseEvent event)
This method returns the tooltip text given a mouse event.
|
String |
getToolTipTextAt(int index)
This method returns the tooltip string for the tab.
|
TabbedPaneUI |
getUI()
This method returns the UI used to display the JTabbedPane.
|
String |
getUIClassID()
This method returns a string identifier that is used to determine which
UI will be used with the JTabbedPane.
|
int |
indexAtLocation(int x,
int y)
This method returns a tab index given an (x,y) location.
|
int |
indexOfComponent(Component component)
This method finds the index of a tab given the component.
|
int |
indexOfTab(Icon icon)
This method finds the index of a tab given the icon.
|
int |
indexOfTab(String title)
This method finds the index of a tab given the title.
|
void |
insertTab(String title,
Icon icon,
Component component,
String tip,
int index)
This method inserts tabs into JTabbedPane.
|
boolean |
isEnabledAt(int index)
This method returns whether this tab is enabled.
|
protected String |
paramString()
Returns a string describing the attributes for the
JTabbedPane component, for use in debugging. |
void |
remove(Component component)
Removes the specified Component from the JTabbedPane.
|
void |
remove(int index)
Removes the tab and component which corresponds to the specified index.
|
void |
removeAll()
This method removes all tabs and associated components from the
JTabbedPane.
|
void |
removeChangeListener(ChangeListener l)
This method removes a ChangeListener to the JTabbedPane.
|
void |
removeTabAt(int index)
Removes the tab at index.
|
void |
setBackgroundAt(int index,
Color background)
This method sets the background color of the tab.
|
void |
setComponentAt(int index,
Component component)
This method sets the component associated with the tab.
|
void |
setDisabledIconAt(int index,
Icon disabledIcon)
This method sets the disabled icon of the tab.
|
void |
setDisplayedMnemonicIndexAt(int tabIndex,
int mnemonicIndex)
This method sets the displayed mnemonic index of the tab.
|
void |
setEnabledAt(int index,
boolean enabled)
This method sets whether the tab is enabled.
|
void |
setForegroundAt(int index,
Color foreground)
This method sets the foreground color of the tab.
|
void |
setIconAt(int index,
Icon icon)
This method sets the icon of the tab.
|
void |
setMnemonicAt(int tabIndex,
int mnemonic)
This method sets the mnemonic for the tab.
|
void |
setModel(SingleSelectionModel m)
This method changes the model property of the JTabbedPane.
|
void |
setSelectedComponent(Component c)
This method sets the component at the selected index.
|
void |
setSelectedIndex(int index)
This method sets the selected index.
|
void |
setTabLayoutPolicy(int tabLayoutPolicy)
This method changes the tabLayoutPolicy property of the JTabbedPane.
|
void |
setTabPlacement(int tabPlacement)
This method changes the tabPlacement property of the JTabbedPane.
|
void |
setTitleAt(int index,
String title)
This method sets the title of the tab.
|
void |
setToolTipTextAt(int index,
String toolTipText)
This method sets the tooltip text of the tab.
|
void |
setUI(TabbedPaneUI ui)
This method sets the UI used to display the JTabbedPane.
|
void |
updateUI()
This method restores the UI to the defaults given by the UIManager.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected ChangeEvent changeEvent
protected ChangeListener changeListener
protected SingleSelectionModel model
public static final int SCROLL_TAB_LAYOUT
public static final int WRAP_TAB_LAYOUT
protected int tabPlacement
public JTabbedPane()
public JTabbedPane(int tabPlacement)
tabPlacement
, where tabPlacement
can be one
of the following values: SwingConstants.TOP
, SwingConstants.BOTTOM
, SwingConstants.LEFT
or
SwingConstants.RIGHT
.tabPlacement
- where the tabs will be placedpublic JTabbedPane(int tabPlacement, int tabLayoutPolicy)
tabPlacement
and tabLayoutPolicy
. The tabPlacement
can be one
of the following values: SwingConstants.TOP
, SwingConstants.BOTTOM
, SwingConstants.LEFT
or
SwingConstants.RIGHT
. The tabLayoutPolicy
can be either
SCROLL_TAB_LAYOUT
or WRAP_TAB_LAYOUT
.tabPlacement
- where the tabs will be placedtabLayoutPolicy
- the way tabs will be placedIllegalArgumentException
- If tabLayoutPolicy or tabPlacement are
not valid.public TabbedPaneUI getUI()
public void setUI(TabbedPaneUI ui)
ui
- The UI used to display the JTabbedPane.public void updateUI()
updateUI
in class JComponent
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
protected ChangeListener createChangeListener()
public void addChangeListener(ChangeListener l)
l
- The ChangeListener to add.public void removeChangeListener(ChangeListener l)
l
- The ChangeListener to remove.protected void fireStateChanged()
public ChangeListener[] getChangeListeners()
public SingleSelectionModel getModel()
public void setModel(SingleSelectionModel m)
m
- The new model to use with the JTabbedPane.public int getTabPlacement()
public void setTabPlacement(int tabPlacement)
tabPlacement
- The tabPlacement to use.IllegalArgumentException
- If tabPlacement is not one of TOP,
BOTTOM, LEFT, or RIGHT.public int getTabLayoutPolicy()
public void setTabLayoutPolicy(int tabLayoutPolicy)
tabLayoutPolicy
- The tabLayoutPolicy to use.IllegalArgumentException
- If tabLayoutPolicy is not one of
SCROLL_TAB_LAYOUT or WRAP_TAB_LAYOUT.public int getSelectedIndex()
public void setSelectedIndex(int index)
index
- The index to set it at.public Component getSelectedComponent()
public void setSelectedComponent(Component c)
c
- The component associated with the selected index.public void insertTab(String title, Icon icon, Component component, String tip, int index)
title
- the title of the tab; may be null
icon
- the tab's icon; may be null
component
- the component associated with the tabtip
- the tooltip for the tabindex
- the index to insert the tab atpublic void addTab(String title, Icon icon, Component component, String tip)
title
- the title of the tab; may be null
icon
- the icon for the tab; may be null
component
- the associated componenttip
- the associated tooltippublic void addTab(String title, Icon icon, Component component)
title
- the title of the tab; may be null
icon
- the icon for the tab; may be null
component
- the associated componentpublic void addTab(String title, Component component)
title
- the title of the tab; may be null
component
- the associated componentpublic Component add(Component component)
public Component add(String title, Component component)
add
in class Container
title
- the title of the tab; may be null
component
- the associated componentContainer.add(Component,Object)
public Component add(Component component, int index)
public void add(Component component, Object constraints)
public void add(Component component, Object constraints, int index)
public void removeTabAt(int index)
index
- The index of the tab to remove.public void remove(Component component)
public void remove(int index)
public void removeAll()
public int getTabCount()
public int getTabRunCount()
public String getTitleAt(int index)
index
- The index of the tab.public Icon getIconAt(int index)
index
- The index of the tab.public Icon getDisabledIconAt(int index)
index
- The index of the tab.public String getToolTipTextAt(int index)
index
- The index of the tab.public Color getForegroundAt(int index)
index
- The index of the tab.public Color getBackgroundAt(int index)
index
- The index of the tab.public Component getComponentAt(int index)
index
- The index of the tab.public boolean isEnabledAt(int index)
index
- The index of the tab.public int getMnemonicAt(int tabIndex)
tabIndex
- The index of the tab.public int getDisplayedMnemonicIndexAt(int tabIndex)
tabIndex
- The index of the tab.public Rectangle getBoundsAt(int index)
index
- The index of the tab.public void setTitleAt(int index, String title)
index
- The index of the tab.title
- The new title.public void setIconAt(int index, Icon icon)
index
- The index of the tab.icon
- The new icon.public void setDisabledIconAt(int index, Icon disabledIcon)
index
- The index of the tab.disabledIcon
- The new disabled icon.public void setToolTipTextAt(int index, String toolTipText)
index
- The index of the tab.toolTipText
- The tooltip text.public void setBackgroundAt(int index, Color background)
index
- The index of the tab.background
- The background color of the tab.public void setForegroundAt(int index, Color foreground)
index
- The index of the tab.foreground
- The foreground color of the tab.public void setEnabledAt(int index, boolean enabled)
index
- The index of the tab.enabled
- Whether the tab is enabled.public void setComponentAt(int index, Component component)
index
- The index of the tab.component
- The component associated with the tab.public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex)
tabIndex
- The index of the tab.mnemonicIndex
- The mnemonic index.public void setMnemonicAt(int tabIndex, int mnemonic)
tabIndex
- The index of the tab.mnemonic
- The mnemonic.public int indexOfTab(String title)
title
- The title that belongs to a tab.public int indexOfTab(Icon icon)
icon
- The icon that belongs to a tab.public int indexOfComponent(Component component)
component
- A component associated with a tab.public int indexAtLocation(int x, int y)
x
- The x coordinate of the point.y
- The y coordinate of the point.public String getToolTipText(MouseEvent event)
getToolTipText
in class JComponent
event
- The mouse event.JComponent.setToolTipText(java.lang.String)
,
JComponent.getToolTipText()
protected String paramString()
JTabbedPane
component, for use in debugging. The return
value is guaranteed to be non-null
, but the format of the
string may vary between implementations.paramString
in class JComponent
JTabbedPane
.public AccessibleContext getAccessibleContext()
JTabbedPane
component.getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
JTabbedPane.AccessibleJTabbedPane
).