net.infonode.tabbedpanel

Class Tab

public class Tab extends JPanel

A Tab is a component that represents a tab in a {@link 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 {@link TitledTab}. In most cases {@link TitledTab} 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:

Version: $Revision: 1.33 $

Author: $Author: jesper $

See Also: TabListener TabbedPanel TitledTab

Constructor Summary
Tab()
Constructs a tab without a content component and this tab as event component
Tab(JComponent contentComponent)
Constructs a tab with a content component and this tab as event component
Method Summary
voidaddNotify()
voidaddTabListener(TabListener listener)
Adds a TabListener
JComponentgetContentComponent()
Gets the content component
JComponent[]getEventComponents()
Gets the event components for this Tab
JComponentgetFocusableComponent()
Gets the component in this tab that is focusable
intgetIndex()
Gets the index of this tab in the TabbedPanel.
ShapegetShape()

Gets the tab {@link Shape}.

This returns the shape of the tab.

TabbedPanelgetTabbedPanel()
Gets the TabbedPanel that this tab is a member of
booleanisHighlighted()
Returns if this tab is highlighted in the TabbedPanel that it is a member of.
booleanisSelected()
Returns if this tab is selected in the TabbedPanel that it is a member of.
voidremoveNotify()
voidremoveTabListener(TabListener listener)
Removes a TabListener
voidsetEnabled(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.

voidsetEventComponent(JComponent eventComponent)

Sets the event component.

voidsetEventComponents(JComponent[] eventComponents)

Sets a list of event components.

voidsetFocusableComponent(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

voidsetHighlighted(boolean highlighted)
Highlights this tab.
voidsetSelected(boolean selected)

Selects this tab.

protected voidsetTabbedPanel(TabbedPanel tabbedPanel)
Called by the tabbed panel when the tab becomes a member or is no longer a member of the tabbed panel

Constructor Detail

Tab

public Tab()
Constructs a tab without a content component and this tab as event component

See Also: Tab

Tab

public Tab(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: Tab

Method Detail

addNotify

public void addNotify()

addTabListener

public void addTabListener(TabListener listener)
Adds a TabListener

Parameters: listener the TabListener to add

getContentComponent

public JComponent getContentComponent()
Gets the content component

Returns: the content component for this tab or null if this Tab doesn't have a content component

getEventComponents

public JComponent[] getEventComponents()
Gets the event components for this Tab

Returns: a list of all event components for this tab

getFocusableComponent

public 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

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.

getShape

public Shape getShape()

Gets the tab {@link 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 {@link Shape}, null if the tab has the normal component rectangle shape

Since: ITP 1.2.0

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

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

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

removeNotify

public void removeNotify()

removeTabListener

public void removeTabListener(TabListener listener)
Removes a TabListener

Parameters: listener the TabListener to remove

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.

Parameters: enabled true for enabled, otherwise false

setEventComponent

public void setEventComponent(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(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

setFocusableComponent

public void setFocusableComponent(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

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

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

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