Class Tab
- All Implemented Interfaces:
-
Styleable,EventTarget
@DefaultProperty("content") @IDProperty("id") public class Tab extends Object implements EventTarget, Styleable Tabs are placed within a TabPane, where each tab represents a single 'page'.
Tabs can contain any Node such as UI controls or groups of nodes added to a layout container.
When the user clicks on a Tab in the TabPane the Tab content becomes visible to the user.
- Since:
- JavaFX 2.0
Property Summary
| Type | Property | Description |
|---|---|---|
final BooleanProperty |
closable |
The closable state for this tab. |
final ObjectProperty |
content |
The content associated with the tab. |
final ObjectProperty |
contextMenu |
The context menu associated with the tab. |
final ReadOnlyBooleanProperty |
disabled |
Indicates whether or not this Tab is disabled. |
final BooleanProperty |
disable |
Sets the disabled state of this tab. |
final ObjectProperty |
graphic |
The graphic in the tab. |
final StringProperty |
id |
The id of this tab. |
final ObjectProperty |
onClosed |
The event handler that is associated with the tab when the tab is closed. |
final ObjectProperty |
onCloseRequest |
Called when there is an external request to close this Tab. |
final ObjectProperty |
onSelectionChanged |
The event handler that is associated with a selection on the tab. |
final ReadOnlyBooleanProperty |
selected |
The currently selected tab. |
final StringProperty |
style |
The CSS style string associated to this tab. |
final ReadOnlyObjectProperty |
tabPane |
The TabPane that contains this tab. |
final StringProperty |
text |
The text shown in the tab. |
final ObjectProperty |
tooltip |
The tooltip associated with this tab. |
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
static final EventType |
CLOSED_EVENT |
Called when a user closes this tab. |
static final EventType |
SELECTION_CHANGED_EVENT |
Called when the tab becomes selected or unselected. |
static final EventType |
TAB_CLOSE_REQUEST_EVENT |
Called when there is an external request to close this Tab. |
Constructor Summary
| Constructor | Description |
|---|---|
Tab() |
Creates a tab with no title. |
Tab |
Creates a tab with a text title. |
Tab |
Creates a tab with a text title and the specified content node. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
final <E extends Event> |
addEventFilter |
Registers an event filter for this target. |
final <E extends Event> |
addEventHandler |
Registers an event handler for this target. |
EventDispatchChain |
buildEventDispatchChain |
Construct an event dispatch chain for this target. |
final BooleanProperty |
closableProperty() |
The closable state for this tab. |
final ObjectProperty |
contentProperty() |
The content associated with the tab. |
final ObjectProperty |
contextMenuProperty() |
The context menu associated with the tab. |
final ReadOnlyBooleanProperty |
disabledProperty() |
Indicates whether or not this Tab is disabled. |
final BooleanProperty |
disableProperty() |
Sets the disabled state of this tab. |
static List |
getClassCssMetaData() |
Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses. |
final Node |
getContent() |
The content associated with the tab. |
final ContextMenu |
getContextMenu() |
The context menu associated with the tab. |
List |
getCssMetaData() |
The CssMetaData of this Styleable. |
final Node |
getGraphic() |
The graphic shown in the tab. |
final String |
getId() |
The id of this tab. |
final EventHandler |
getOnClosed() |
The event handler that is associated with the tab when the tab is closed. |
EventHandler |
getOnCloseRequest() |
Gets the value of the onCloseRequest property. |
final EventHandler |
getOnSelectionChanged() |
The event handler that is associated with a selection on the tab. |
final ObservableMap |
getProperties() |
Returns an observable map of properties on this Tab for use primarily by application developers. |
final ObservableSet |
getPseudoClassStates() |
Return the pseudo-class state of this Styleable. |
final String |
getStyle() |
The CSS style string associated to this tab. |
Styleable |
getStyleableParent() |
Return the parent of this Styleable, or null if there is no parent. |
ObservableList |
getStyleClass() |
A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine. |
final TabPane |
getTabPane() |
A reference to the TabPane that contains this tab instance. |
final String |
getText() |
The text shown in the tab. |
final Tooltip |
getTooltip() |
The tooltip associated with this tab. |
String |
getTypeSelector() |
The type of this Styleable that is to be used in selector matching. |
Object |
getUserData() |
Returns a previously set Object property, or null if no such property has been set using the setUserData(java.lang.Object) method. |
final ObjectProperty |
graphicProperty() |
The graphic in the tab. |
boolean |
hasProperties() |
Tests if this Tab has properties. |
final StringProperty |
idProperty() |
The id of this tab. |
final boolean |
isClosable() |
Returns true if this tab is closable. |
final boolean |
isDisable() |
Returns true if this tab is disable. |
final boolean |
isDisabled() |
|
final boolean |
isSelected() |
Represents whether this tab is the currently selected tab, To change the selected Tab use tabPane.getSelectionModel().select()
|
final ObjectProperty |
onClosedProperty() |
The event handler that is associated with the tab when the tab is closed. |
final ObjectProperty |
onCloseRequestProperty() |
Called when there is an external request to close this Tab. |
final ObjectProperty |
onSelectionChangedProperty() |
The event handler that is associated with a selection on the tab. |
final <E extends Event> |
removeEventFilter |
Unregisters a previously registered event filter from this target. |
final <E extends Event> |
removeEventHandler |
Unregisters a previously registered event handler from this target. |
final ReadOnlyBooleanProperty |
selectedProperty() |
The currently selected tab. |
final void |
setClosable |
Sets true if the tab is closable. |
final void |
setContent |
The content to show within the main TabPane area. |
final void |
setContextMenu |
Specifies the context menu to show when the user right-clicks on the tab. |
final void |
setDisable |
Sets the disabled state of this tab. |
final void |
setGraphic |
Sets the graphic to show in the tab to allow the user to differentiate between the function of each tab. |
final void |
setId |
Sets the id of this tab. |
final void |
setOnClosed |
Defines a function to be called when the tab is closed. |
void |
setOnCloseRequest |
Sets the value of the onCloseRequest property. |
final void |
setOnSelectionChanged |
Defines a function to be called when a selection changed has occurred on the tab. |
final void |
setStyle |
A string representation of the CSS style associated with this tab. |
final void |
setText |
Sets the text to show in the tab to allow the user to differentiate between the function of each tab. |
final void |
setTooltip |
Specifies the tooltip to show when the user hovers over the tab. |
void |
setUserData |
Convenience method for setting a single Object property that can be retrieved at a later date. |
final StringProperty |
styleProperty() |
The CSS style string associated to this tab. |
final ReadOnlyObjectProperty |
tabPaneProperty() |
The TabPane that contains this tab. |
final StringProperty |
textProperty() |
The text shown in the tab. |
final ObjectProperty |
tooltipProperty() |
The tooltip associated with this tab. |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
Property Details
id
public final StringProperty idProperty
- See Also:
style
public final StringProperty styleProperty
- See Also:
selected
public final ReadOnlyBooleanProperty selectedProperty
- See Also:
tabPane
public final ReadOnlyObjectProperty<TabPane> tabPaneProperty
- See Also:
text
public final StringProperty textProperty
- See Also:
graphic
public final ObjectProperty<Node> graphicProperty
- See Also:
content
public final ObjectProperty<Node> contentProperty
The content associated with the tab.
- See Also:
contextMenu
public final ObjectProperty<ContextMenu> contextMenuProperty
- See Also:
closable
public final BooleanProperty closableProperty
- See Also:
onSelectionChanged
public final ObjectProperty<EventHandler<Event>> onSelectionChangedProperty
- See Also:
onClosed
public final ObjectProperty<EventHandler<Event>> onClosedProperty
- See Also:
tooltip
public final ObjectProperty<Tooltip> tooltipProperty
- See Also:
disable
public final BooleanProperty disableProperty
TabPane.getSelectionModel().- Default value:
- false
- Since:
- JavaFX 2.2
- See Also:
disabled
public final ReadOnlyBooleanProperty disabledProperty
Tab is disabled. A Tab will become disabled if disable is set to true on either itself or if the TabPane is disabled.- Default value:
- false
- Since:
- JavaFX 2.2
- See Also:
onCloseRequest
public final ObjectProperty<EventHandler<Event>> onCloseRequestProperty
Tab. The installed event handler can prevent tab closing by consuming the received event.- Since:
- JavaFX 8.0
- See Also:
Field Details
SELECTION_CHANGED_EVENT
public static final EventType<Event> SELECTION_CHANGED_EVENT
Called when the tab becomes selected or unselected.
CLOSED_EVENT
public static final EventType<Event> CLOSED_EVENT
Called when a user closes this tab. This is useful for freeing up memory.
TAB_CLOSE_REQUEST_EVENT
public static final EventType<Event> TAB_CLOSE_REQUEST_EVENT
Tab. The installed event handler can prevent tab closing by consuming the received event.- Since:
- JavaFX 8.0
Constructor Details
Tab
public Tab()
Tab
public Tab(String text)
- Parameters:
-
text- The title of the tab.
Tab
public Tab(String text, Node content)
- Parameters:
-
text- The title of the tab. -
content- The content of the tab. - Since:
- JavaFX 8u40
Method Details
setId
public final void setId(String value)
TabPane. The default value is null.- Parameters:
-
value- the id of this tab
getId
idProperty
public final StringProperty idProperty()
- Returns:
- the id property of this tab
- See Also:
setStyle
public final void setStyle(String value)
Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.
- Parameters:
-
value- the style string
getStyle
styleProperty
public final StringProperty styleProperty()
- Returns:
- the CSS style string property associated to this tab
- See Also:
isSelected
public final boolean isSelected()
Represents whether this tab is the currently selected tab, To change the selected Tab use tabPane.getSelectionModel().select()
- Returns:
- true if selected
selectedProperty
public final ReadOnlyBooleanProperty selectedProperty()
- Returns:
- the selected tab
- See Also:
getTabPane
public final TabPane getTabPane()
A reference to the TabPane that contains this tab instance.
- Returns:
- the TabPane
tabPaneProperty
public final ReadOnlyObjectProperty<TabPane> tabPaneProperty()
- Returns:
- the TabPane property
- See Also:
setText
public final void setText(String value)
Sets the text to show in the tab to allow the user to differentiate between the function of each tab. The text is always visible
- Parameters:
-
value- the text string
getText
public final String getText()
- Returns:
- The text shown in the tab.
textProperty
public final StringProperty textProperty()
- Returns:
- the text property
- See Also:
setGraphic
public final void setGraphic(Node value)
Sets the graphic to show in the tab to allow the user to differentiate between the function of each tab. By default the graphic does not rotate based on the TabPane.tabPosition value, but it can be set to rotate by setting TabPane.rotateGraphic to true.
- Parameters:
-
value- the graphic node
getGraphic
public final Node getGraphic()
- Returns:
- The graphic shown in the tab.
graphicProperty
public final ObjectProperty<Node> graphicProperty()
- Returns:
- The graphic in the tab.
- See Also:
setContent
public final void setContent(Node value)
The content to show within the main TabPane area. The content can be any Node such as UI controls or groups of nodes added to a layout container.
- Parameters:
-
value- the content node
getContent
public final Node getContent()
The content associated with the tab.
- Returns:
- The content associated with the tab.
contentProperty
public final ObjectProperty<Node> contentProperty()
The content associated with the tab.
- Returns:
- the content property
- See Also:
setContextMenu
public final void setContextMenu(ContextMenu value)
Specifies the context menu to show when the user right-clicks on the tab.
- Parameters:
-
value- the context menu
getContextMenu
public final ContextMenu getContextMenu()
- Returns:
- The context menu associated with the tab.
contextMenuProperty
public final ObjectProperty<ContextMenu> contextMenuProperty()
- Returns:
- the context menu property
- See Also:
setClosable
public final void setClosable(boolean value)
Sets true if the tab is closable. If this is set to false, then regardless of the TabClosingPolicy, it will not be possible for the user to close this tab. Therefore, when this property is false, no 'close' button will be shown on the tab. The default is true.
- Parameters:
-
value- the closable value
isClosable
public final boolean isClosable()
true if this tab is closable.- Returns:
-
trueif the tab is closable.
closableProperty
public final BooleanProperty closableProperty()
- Returns:
- the closable property
- See Also:
setOnSelectionChanged
public final void setOnSelectionChanged(EventHandler<Event> value)
- Parameters:
-
value- the on selection changed event handler
getOnSelectionChanged
public final EventHandler<Event> getOnSelectionChanged()
- Returns:
- The event handler that is associated with a tab selection.
onSelectionChangedProperty
public final ObjectProperty<EventHandler<Event>> onSelectionChangedProperty()
- Returns:
- the on selection changed event handler property
- See Also:
setOnClosed
public final void setOnClosed(EventHandler<Event> value)
- Parameters:
-
value- the on closed event handler
getOnClosed
public final EventHandler<Event> getOnClosed()
- Returns:
- The event handler that is associated with the tab when the tab is closed.
onClosedProperty
public final ObjectProperty<EventHandler<Event>> onClosedProperty()
- Returns:
- the on closed event handler property
- See Also:
setTooltip
public final void setTooltip(Tooltip value)
Specifies the tooltip to show when the user hovers over the tab.
- Parameters:
-
value- the tool tip value
getTooltip
public final Tooltip getTooltip()
- Returns:
- The tooltip associated with this tab.
tooltipProperty
public final ObjectProperty<Tooltip> tooltipProperty()
- Returns:
- the tool tip property
- See Also:
setDisable
public final void setDisable(boolean value)
- Default value:
- false
- Parameters:
-
value- the state to set this tab - Since:
- JavaFX 2.2
isDisable
public final boolean isDisable()
true if this tab is disable.- Returns:
- true if this tab is disable
- Since:
- JavaFX 2.2
disableProperty
public final BooleanProperty disableProperty()
TabPane.getSelectionModel().- Default value:
- false
- Returns:
- the disable property
- Since:
- JavaFX 2.2
- See Also:
isDisabled
public final boolean isDisabled()
- Returns:
- true if the TabPane is disabled
- Since:
- JavaFX 2.2
disabledProperty
public final ReadOnlyBooleanProperty disabledProperty()
Tab is disabled. A Tab will become disabled if disable is set to true on either itself or if the TabPane is disabled.- Default value:
- false
- Returns:
- the disabled property
- Since:
- JavaFX 2.2
- See Also:
onCloseRequestProperty
public final ObjectProperty<EventHandler<Event>> onCloseRequestProperty()
Tab. The installed event handler can prevent tab closing by consuming the received event.- Returns:
- the
onCloseRequestproperty - Since:
- JavaFX 8.0
- See Also:
getOnCloseRequest
public EventHandler<Event> getOnCloseRequest()
onCloseRequest property.- Property description:
- Called when there is an external request to close this
Tab. The installed event handler can prevent tab closing by consuming the received event. - Returns:
- the value of the
onCloseRequestproperty - Since:
- JavaFX 8.0
- See Also:
setOnCloseRequest
public void setOnCloseRequest(EventHandler<Event> value)
onCloseRequest property.- Property description:
- Called when there is an external request to close this
Tab. The installed event handler can prevent tab closing by consuming the received event. - Parameters:
-
value- the value for theonCloseRequestproperty - Since:
- JavaFX 8.0
- See Also:
getProperties
public final ObservableMap<Object,Object> getProperties()
- Returns:
- an observable map of properties on this Tab for use primarily by application developers
- Since:
- JavaFX 2.2
hasProperties
public boolean hasProperties()
- Returns:
- true if this tab has properties.
- Since:
- JavaFX 2.2
setUserData
public void setUserData(Object value)
getUserData().- Parameters:
-
value- The value to be stored - this can later be retrieved by callinggetUserData(). - Since:
- JavaFX 2.2
getUserData
public Object getUserData()
setUserData(java.lang.Object) method.- Returns:
- The Object that was previously set, or null if no property has been set or if null was set.
- Since:
- JavaFX 2.2
getStyleClass
public ObservableList<String> getStyleClass()
- Specified by:
-
getStyleClassin interfaceStyleable - Returns:
- a list of String identifiers which can be used to logically group Nodes, specifically for an external style engine
- See Also:
buildEventDispatchChain
public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
EventTargetEventTarget. This event target is not automatically added to the chain, so if it wants to process events, it needs to add an EventDispatcher for itself to the chain. In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target.
The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain.
The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain.
- Specified by:
-
buildEventDispatchChainin interfaceEventTarget - Parameters:
-
tail- the initial chain to build from - Returns:
- the resulting event dispatch chain for this target
addEventHandler
public final <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)
EventTarget The handler is called when the target receives an Event of the specified type during the bubbling phase of event delivery.
- Specified by:
-
addEventHandlerin interfaceEventTarget - Type Parameters:
-
E- the event class of the handler - Parameters:
-
eventType- the type of the events received by the handler -
eventHandler- the event handler
removeEventHandler
public final <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)
EventTarget Since it is possible to register a single EventHandler instance for different event types, the caller needs to specify the event type from which the handler should be unregistered.
- Specified by:
-
removeEventHandlerin interfaceEventTarget - Type Parameters:
-
E- the event class of the handler - Parameters:
-
eventType- the event type from which to unregister -
eventHandler- the event handler
addEventFilter
public final <E extends Event> void addEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter)
EventTarget The filter is called when the target receives an Event of the specified type during the capturing phase of event delivery.
- Specified by:
-
addEventFilterin interfaceEventTarget - Type Parameters:
-
E- the event class of the filter - Parameters:
-
eventType- the type of the events received by the filter -
eventFilter- the event filter
removeEventFilter
public final <E extends Event> void removeEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter)
EventTarget Since it is possible to register a single EventHandler instance for different event types, the caller needs to specify the event type from which the filter should be unregistered.
- Specified by:
-
removeEventFilterin interfaceEventTarget - Type Parameters:
-
E- the event class of the filter - Parameters:
-
eventType- the event type from which to unregister -
eventFilter- the event filter
getTypeSelector
public String getTypeSelector()
Styleable that is to be used in selector matching. This is analogous to an "element" in HTML. (CSS Type Selector).- Specified by:
-
getTypeSelectorin interfaceStyleable - Returns:
- "Tab"
- Since:
- JavaFX 8.0
getStyleableParent
public Styleable getStyleableParent()
- Specified by:
-
getStyleableParentin interfaceStyleable - Returns:
getTabPane()- Since:
- JavaFX 8.0
getPseudoClassStates
public final ObservableSet<PseudoClass> getPseudoClassStates()
- Specified by:
-
getPseudoClassStatesin interfaceStyleable - Returns:
- the pseudo-class state
- Since:
- JavaFX 8.0
getCssMetaData
public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
- Specified by:
-
getCssMetaDatain interfaceStyleable - Returns:
- the CssMetaData
- Since:
- JavaFX 8.0
getClassCssMetaData
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
CssMetaData associated with this class, which may include the CssMetaData of its superclasses.- Returns:
- the
CssMetaData - Since:
- JavaFX 8.0
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.