Class Tab
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- net.infonode.tabbedpanel.Tab
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
- Direct Known Subclasses:
TitledTab
public class Tab extends javax.swing.JPanel
A Tab is a component that represents a tab in a
TabbedPanel
.A tab can hold a content component. The content component will then be shown in the content area of the TabbedPanel that the tab is a member of when the tab is selected. If the tab doesn't have a content component, then the TabbedPanel will not show any content in the content area, i.e. it will be empty.
The tab is basically a JPanel with a BorderLayout. The layout manager can be changed using setLayout. Components and borders can be added and removed from the tab. The tab can also be subclassed to create other types of tabs, see
TitledTab
. In most casesTitledTab
is the preferred tab type to use because TitledTab adds support for a text, icon, looks etc.The tab component will be shown in the tab area of a TabbedPanel after the tab has become a member of that TabbedPanel by either adding or inserting it. A tab can only be a member of one TabbedPanel at the same time.
A tab can have different states when it is a member of a TabbedPanel:
- Normal: This means that the tab is shown (and not selected) in the TabbedPanel. The content component is not shown until the user selects the tab.
- Highlighted: This means that for some reason the tab should be highlighted in the TabbedPanel. Highlighted could mean that the user pressed the tab with the mouse and has not yet released the mouse, i.e. it has not been selected yet.
- Selected: This means that the tab is selected in the TabbedPanel. The TabbedPanel will then show the Tab's content component (if any). A selected tab will also be be highlighted before it is selected.
- Enabled: This means that the tab is enabled and can be selected, highlighted dragged, moved etc.
- Disabled: This means that the tab cannot be selected, highlighted dragged, moved etc.
- See Also:
TabListener
,TabbedPanel
,TitledTab
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNotify()
void
addTabListener(TabListener listener)
Adds a TabListenerjavax.swing.JComponent
getContentComponent()
Gets the content componentjavax.swing.JComponent[]
getEventComponents()
Gets the event components for this Tabjavax.swing.JComponent
getFocusableComponent()
Gets the component in this tab that is focusableint
getIndex()
Gets the index of this tab in the TabbedPanel.java.awt.Shape
getShape()
Gets the tabShape
.TabbedPanel
getTabbedPanel()
Gets the TabbedPanel that this tab is a member ofboolean
isHighlighted()
Returns if this tab is highlighted in the TabbedPanel that it is a member of.boolean
isSelected()
Returns if this tab is selected in the TabbedPanel that it is a member of.void
removeNotify()
void
removeTabListener(TabListener listener)
Removes a TabListenervoid
setEnabled(boolean enabled)
Enable or disable this tab.void
setEventComponent(javax.swing.JComponent eventComponent)
Sets the event component.void
setEventComponents(javax.swing.JComponent[] eventComponents)
Sets a list of event components.void
setFocusableComponent(javax.swing.JComponent focusableComponent)
Sets the component in this tab that represents the focusable part of the tab.void
setHighlighted(boolean highlighted)
Highlights this tab.void
setSelected(boolean selected)
Selects this tab.protected void
setTabbedPanel(TabbedPanel tabbedPanel)
Called by the tabbed panel when the tab becomes a member or is no longer a member of the tabbed panel-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
Tab
public Tab()
Constructs a tab without a content component and this tab as event component
-
Tab
public Tab(javax.swing.JComponent contentComponent)
Constructs a tab with a content component and this tab as event component- Parameters:
contentComponent
- content component for this tab or null for no content component.- See Also:
setEventComponent(javax.swing.JComponent)
-
-
Method Detail
-
addTabListener
public void addTabListener(TabListener listener)
Adds a TabListener- Parameters:
listener
- the TabListener to add
-
removeTabListener
public void removeTabListener(TabListener listener)
Removes a TabListener- Parameters:
listener
- the TabListener to remove
-
getContentComponent
public javax.swing.JComponent getContentComponent()
Gets the content component- Returns:
- the content component for this tab or null if this Tab doesn't have a content component
-
getTabbedPanel
public TabbedPanel getTabbedPanel()
Gets the TabbedPanel that this tab is a member of- Returns:
- the TabbedPanel or null if this tab is not a member of any TabbedPanel
-
setEnabled
public void setEnabled(boolean enabled)
Enable or disable this tab.
If the tab is disabled, then the tab will not signal any events until it is enabled again.
- Overrides:
setEnabled
in classjavax.swing.JComponent
- Parameters:
enabled
- true for enabled, otherwise false
-
setSelected
public void setSelected(boolean selected)
Selects this tab. A tab can only have the selected state if it is a member of a TabbedPanel.
Setting selected to true means that this tab will be the selected tab in the TabbedPanel it is a member of. If this tab is the selected tab in the TabbedPanel then setting selected to false means there will be no selected tab in the TabbedPanel until another tab is selected.
- Parameters:
selected
- True for selected, otherwise false
-
isSelected
public boolean isSelected()
Returns if this tab is selected in the TabbedPanel that it is a member of.- Returns:
- true if selected, false if not selected or this tab is not member of a TabbedPanel
-
setHighlighted
public void setHighlighted(boolean highlighted)
Highlights this tab. This tab will be the highlighted tab in the TabbedPanel that it is member of.- Parameters:
highlighted
- true for highlight, otherwise false
-
isHighlighted
public boolean isHighlighted()
Returns if this tab is highlighted in the TabbedPanel that it is a member of.- Returns:
- true if highlighted, false if not highlighted or this tab is not member of a TabbedPanel
-
setEventComponent
public void setEventComponent(javax.swing.JComponent eventComponent)
Sets the event component. An event component is a component in the tab that is used for internal listening to mouse events on the tab.
Note: The event component must be part of this Tab
- Parameters:
eventComponent
- a component in this tab that should be used for mouse event listening
-
setEventComponents
public void setEventComponents(javax.swing.JComponent[] eventComponents)
Sets a list of event components. An event component is a component in the tab that is used for internal listening to mouse events on the tab. This method makes it possible to use several components in the tab as event components.
Note: The event components must be part of this Tab
- Parameters:
eventComponents
- a list of components in this tab that should be used for mouse event listening
-
getEventComponents
public javax.swing.JComponent[] getEventComponents()
Gets the event components for this Tab- Returns:
- a list of all event components for this tab
-
getIndex
public int getIndex()
Gets the index of this tab in the TabbedPanel.- Returns:
- the tab index, -1 if this tab is not a member of a TabbedPanel.
-
getFocusableComponent
public javax.swing.JComponent getFocusableComponent()
Gets the component in this tab that is focusable- Returns:
- focusable component or null if this tab doesn't have any focusable component
-
setFocusableComponent
public void setFocusableComponent(javax.swing.JComponent focusableComponent)
Sets the component in this tab that represents the focusable part of the tab.
Note: The focusable component must be part of this Tab
- Parameters:
focusableComponent
- a component in this tab or null if no component should be focusable
-
getShape
public java.awt.Shape getShape()
Gets the tab
Shape
.This returns the shape of the tab. This can be be used by for example content borders in the tabbed panel so they can skip a gap where the tab intersects the tabbed panel content area.
- Returns:
- the tab
Shape
, null if the tab has the normal component rectangle shape - Since:
- ITP 1.2.0
-
setTabbedPanel
protected void setTabbedPanel(TabbedPanel tabbedPanel)
Called by the tabbed panel when the tab becomes a member or is no longer a member of the tabbed panel- Parameters:
tabbedPanel
- tabbed panel that this tab is a member of or null if this tab is no longer a member o a tabbed panel
-
addNotify
public void addNotify()
- Overrides:
addNotify
in classjavax.swing.JComponent
-
removeNotify
public void removeNotify()
- Overrides:
removeNotify
in classjavax.swing.JComponent
-
-