Class Tab

java.lang.Object
javafx.scene.control.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 Details

  • 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
      Called when there is an external request to close this Tab. The installed event handler can prevent tab closing by consuming the received event.
      Since:
      JavaFX 8.0
  • Constructor Details

    • Tab

      public Tab()
      Creates a tab with no title.
    • Tab

      public Tab​(String text)
      Creates a tab with a text title.
      Parameters:
      text - The title of the tab.
    • Tab

      public Tab​(String text, Node content)
      Creates a tab with a text title and the specified content node.
      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)
      Sets the id of this tab. This simple string identifier is useful for finding a specific Tab within the TabPane. The default value is null.
      Parameters:
      value - the id of this tab
    • getId

      public final String getId()
      The id of this tab.
      Specified by:
      getId in interface Styleable
      Returns:
      The id of the tab.
    • idProperty

      public final StringProperty idProperty()
      The id of this tab.
      See Also:
      getId(), setId(String)
    • setStyle

      public final void setStyle​(String value)
      A string representation of the CSS style associated with this tab. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.

      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

      public final String getStyle()
      The CSS style string associated to this tab.
      Specified by:
      getStyle in interface Styleable
      Returns:
      The CSS style string associated to this tab.
    • styleProperty

      public final StringProperty styleProperty()
      The CSS style string associated to this tab.
      See Also:
      getStyle(), setStyle(String)
    • 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()
      The currently selected tab.
      See Also:
      isSelected()
    • getTabPane

      public final TabPane getTabPane()

      A reference to the TabPane that contains this tab instance.

      Returns:
      the TabPane
    • tabPaneProperty

      public final ReadOnlyObjectProperty<TabPane> tabPaneProperty()
      The TabPane that contains this tab.
      See Also:
      getTabPane()
    • 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()
      The text shown in the tab.
      Returns:
      The text shown in the tab.
    • textProperty

      public final StringProperty textProperty()
      The text shown in the tab.
      See Also:
      getText(), setText(String)
    • 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()
      The graphic shown in the tab.
      Returns:
      The graphic shown in the tab.
    • graphicProperty

      public final ObjectProperty<Node> graphicProperty()
      The graphic in the tab.
      See Also:
      getGraphic(), setGraphic(Node)
    • 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.

      See Also:
      getContent(), setContent(Node)
    • 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()
      The context menu associated with the tab.
      Returns:
      The context menu associated with the tab.
    • contextMenuProperty

      public final ObjectProperty<ContextMenu> contextMenuProperty()
      The context menu associated with the tab.
      See Also:
      getContextMenu(), setContextMenu(ContextMenu)
    • 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()
      Returns true if this tab is closable.
      Returns:
      true if the tab is closable.
    • closableProperty

      public final BooleanProperty closableProperty()
      The closable state for this tab.
      See Also:
      isClosable(), setClosable(boolean)
    • setOnSelectionChanged

      public final void setOnSelectionChanged​(EventHandler<Event> value)
      Defines a function to be called when a selection changed has occurred on the tab.
      Parameters:
      value - the on selection changed event handler
    • getOnSelectionChanged

      public final EventHandler<Event> getOnSelectionChanged()
      The event handler that is associated with a selection on the tab.
      Returns:
      The event handler that is associated with a tab selection.
    • onSelectionChangedProperty

      public final ObjectProperty<EventHandler<Event>> onSelectionChangedProperty()
      The event handler that is associated with a selection on the tab.
      See Also:
      getOnSelectionChanged(), setOnSelectionChanged(EventHandler)
    • setOnClosed

      public final void setOnClosed​(EventHandler<Event> value)
      Defines a function to be called when the tab is closed.
      Parameters:
      value - the on closed event handler
    • getOnClosed

      public final EventHandler<Event> getOnClosed()
      The event handler that is associated with the tab when the tab is closed.
      Returns:
      The event handler that is associated with the tab when the tab is closed.
    • onClosedProperty

      public final ObjectProperty<EventHandler<Event>> onClosedProperty()
      The event handler that is associated with the tab when the tab is closed.
      See Also:
      getOnClosed(), setOnClosed(EventHandler)
    • 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()
      The tooltip associated with this tab.
      Returns:
      The tooltip associated with this tab.
    • tooltipProperty

      public final ObjectProperty<Tooltip> tooltipProperty()
      The tooltip associated with this tab.
      See Also:
      getTooltip(), setTooltip(Tooltip)
    • setDisable

      public final void setDisable​(boolean value)
      Sets the disabled state of this tab.
      Default value:
      false
      Parameters:
      value - the state to set this tab
      Since:
      JavaFX 2.2
    • isDisable

      public final boolean isDisable()
      Returns true if this tab is disable.
      Returns:
      true if this tab is disable
      Since:
      JavaFX 2.2
    • disableProperty

      public final BooleanProperty disableProperty()
      Sets the disabled state of this tab. A disable tab is no longer interactive or traversable, but the contents remain interactive. A disable tab can be selected using TabPane.getSelectionModel().
      Default value:
      false
      Since:
      JavaFX 2.2
      See Also:
      isDisable(), setDisable(boolean)
    • isDisabled

      public final boolean isDisabled()
      Returns true when the Tab disable is set to true or if the TabPane is disabled.
      Returns:
      true if the TabPane is disabled
      Since:
      JavaFX 2.2
    • disabledProperty

      public final ReadOnlyBooleanProperty disabledProperty()
      Indicates whether or not this 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:
      isDisabled()
    • onCloseRequestProperty

      public final ObjectProperty<EventHandler<Event>> onCloseRequestProperty()
      Called when there is an external request to close this Tab. The installed event handler can prevent tab closing by consuming the received event.
      Since:
      JavaFX 8.0
      See Also:
      getOnCloseRequest(), setOnCloseRequest(EventHandler)
    • getOnCloseRequest

      public EventHandler<Event> getOnCloseRequest()
      Gets the value of the property onCloseRequest.
      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.
      Since:
      JavaFX 8.0
    • setOnCloseRequest

      public void setOnCloseRequest​(EventHandler<Event> value)
      Sets the value of the property onCloseRequest.
      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.
      Since:
      JavaFX 8.0
    • getProperties

      public final ObservableMap<Object,​Object> getProperties()
      Returns an observable map of properties on this Tab for use primarily by application developers.
      Returns:
      an observable map of properties on this Tab for use primarily by application developers
      Since:
      JavaFX 2.2
    • hasProperties

      public boolean hasProperties()
      Tests if this Tab has properties.
      Returns:
      true if this tab has properties.
      Since:
      JavaFX 2.2
    • setUserData

      public void setUserData​(Object value)
      Convenience method for setting a single Object property that can be retrieved at a later date. This is functionally equivalent to calling the getProperties().put(Object key, Object value) method. This can later be retrieved by calling getUserData().
      Parameters:
      value - The value to be stored - this can later be retrieved by calling getUserData().
      Since:
      JavaFX 2.2
    • getUserData

      public Object getUserData()
      Returns a previously set Object property, or null if no such property has been set using the 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()
      A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine. This variable is analogous to the "class" attribute on an HTML element and, as such, each element of the list is a style class to which this Node belongs.
      Specified by:
      getStyleClass in interface Styleable
      Returns:
      a list of String identifiers which can be used to logically group Nodes, specifically for an external style engine
      See Also:
      CSS3 class selectors
    • getTypeSelector

      public String getTypeSelector()
      The type of this Styleable that is to be used in selector matching. This is analogous to an "element" in HTML. (CSS Type Selector).
      Specified by:
      getTypeSelector in interface Styleable
      Returns:
      "Tab"
      Since:
      JavaFX 8.0
    • getStyleableParent

      public Styleable getStyleableParent()
      Return the parent of this Styleable, or null if there is no parent.
      Specified by:
      getStyleableParent in interface Styleable
      Returns:
      getTabPane()
      Since:
      JavaFX 8.0
    • getPseudoClassStates

      public final ObservableSet<PseudoClass> getPseudoClassStates()
      Return the pseudo-class state of this Styleable. CSS assumes this set is read-only.
      Specified by:
      getPseudoClassStates in interface Styleable
      Returns:
      the pseudo-class state
      Since:
      JavaFX 8.0
    • getCssMetaData

      public List<CssMetaData<? extends Styleable,​?>> getCssMetaData()
      The CssMetaData of this Styleable. This may be returned as an unmodifiable list.
      Specified by:
      getCssMetaData in interface Styleable
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,​?>> getClassCssMetaData()
      Returns:
      The CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Since:
      JavaFX 8.0