Class HeaderBar

All Implemented Interfaces:
Styleable, EventTarget

@Deprecated(since="25") public class HeaderBar extends Region
Deprecated.
This is a preview feature which may be changed or removed in a future release.
A client-area header bar that is used as a replacement for the system-provided header bar in stages with the StageStyle.EXTENDED style. This class enables the click-and-drag to move and double-click to maximize behaviors that are usually afforded by system-provided header bars. The entire HeaderBar background is draggable by default, but its content is not. Applications can specify draggable content nodes of the HeaderBar with the dragType property.

HeaderBar is a layout container that allows applications to place scene graph nodes in three areas: left, center, and right. All areas can be null. The default minHeight of the HeaderBar is set to match the height of the platform-specific default header buttons.

Single header bar

Most applications should only add a single HeaderBar to the scene graph, placed at the top of the scene and extending its entire width. This ensures that the reported values for leftSystemInset and rightSystemInset, which describe the area reserved for the system-provided window buttons, correctly align with the location of the HeaderBar and are taken into account when the contents of the HeaderBar are laid out.

Multiple header bars

Applications that use multiple header bars might need to configure the additional padding inserted into the layout to account for the system-reserved areas. For example, when two header bars are placed next to each other in the horizontal direction, the default configuration incorrectly adds additional padding between the two header bars. In this case, the leftSystemPadding and rightSystemPadding properties can be used to remove the padding that is not needed.

Header button height

Applications can specify the preferred height for system-provided header buttons by setting the prefButtonHeight property on the Stage associated with the header bar. This can be used to achieve a more cohesive visual appearance by having the system-provided header buttons match the height of the client-area header bar.

Color scheme

The color scheme of the default header buttons is automatically adjusted to remain easily recognizable by inspecting the Scene.fill property to gauge the brightness of the user interface. Applications should set the scene fill to a color that matches the user interface of the header bar area, even if the scene fill is not visible because it is obscured by other controls.

Custom header buttons

If more control over the header buttons is desired, applications can opt out of the system-provided header buttons by setting the prefButtonHeight property on the Stage associated with the header bar to zero and place custom header buttons in the JavaFX scene graph instead. Any JavaFX control can be used as a custom header button by specifying its semantic type with the buttonType property.

System menu

Some platforms support a system menu that can be summoned by right-clicking the draggable area. The system menu will not be shown when:
  1. the Stage is in full-screen mode, or
  2. the HeaderBar has consumed the ContextMenuEvent.CONTEXT_MENU_REQUESTED event.

Layout constraints

The left and right children will be resized to their preferred widths and extend the height of the HeaderBar. The center child will be resized to fill the available space. HeaderBar honors the minimum, preferred, and maximum sizes of its children. If a child's resizable range prevents it from be resized to fit within its position, it will be vertically centered relative to the available space; this alignment can be customized with a layout constraint.

An application may set constraints on individual children to customize their layout. For each constraint, HeaderBar provides static getter and setter methods.

Layout constraints of HeaderBar
ConstraintTypeDescription
alignmentPos The alignment of the child within its area of the HeaderBar.
margin InsetsMargin space around the outside of the child.

Special layout of centered child

If a child is configured to be centered in the center area (i.e. its alignment constraint is either null, Pos.CENTER, Pos.TOP_CENTER, or Pos.BOTTOM_CENTER), it will be centered with respect to the entire header bar, and not with respect to the center area only. This means that, for a header bar that extends the entire width of the Stage, the child will appear to be horizontally centered within the Stage.

If a child should instead be centered with respect to the center area only, a possible solution is to place another layout container like BorderPane in the center area, and then center the child within the other layout container.

Example

Usually, HeaderBar is placed in a root container like BorderPane to align it with the top of the scene:
public class MyApp extends Application {
    @Override
    public void start(Stage stage) {
        var button = new Button("My button");
        HeaderBar.setAlignment(button, Pos.CENTER_LEFT);
        HeaderBar.setMargin(button, new Insets(5));

        var headerBar = new HeaderBar();
        headerBar.setCenter(button);

        var root = new BorderPane();
        root.setTop(headerBar);

        stage.setScene(new Scene(root));
        stage.initStyle(StageStyle.EXTENDED);
        stage.show();
    }
}
Since:
25
  • Property Details

    • left

      public final ObjectProperty<Node> leftProperty
      The left area of the HeaderBar.
      Default value:
      null
      Since:
      26
      See Also:
    • center

      public final ObjectProperty<Node> centerProperty
      The center area of the HeaderBar.
      Default value:
      null
      See Also:
    • right

      public final ObjectProperty<Node> rightProperty
      The right area of the HeaderBar.
      Default value:
      null
      Since:
      26
      See Also:
    • leftSystemPadding

      public final BooleanProperty leftSystemPaddingProperty
      Specifies whether additional padding should be added to the left side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the left side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Since:
      26
      See Also:
    • rightSystemPadding

      public final BooleanProperty rightSystemPaddingProperty
      Specifies whether additional padding should be added to the right side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the right side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Since:
      26
      See Also:
  • Field Details

    • USE_DEFAULT_SIZE

      public static final double USE_DEFAULT_SIZE
      Deprecated.
      Sentinel value that can be used for the prefButtonHeight property to indicate that the platform should choose the platform-specific default button height.
      See Also:
  • Constructor Details

    • HeaderBar

      public HeaderBar()
      Deprecated.
      Creates a new HeaderBar.
    • HeaderBar

      public HeaderBar(Node left, Node center, Node right)
      Deprecated.
      Creates a new HeaderBar with the specified children.
      Parameters:
      left - the left node, or null
      center - the center node, or null
      right - the right node, or null
  • Method Details

    • setDragType

      public static void setDragType(Node child, HeaderDragType value)
      Deprecated.
      Sets the value of the dragType property for the specified child.
      Parameters:
      child - the child node
      value - the HeaderDragType, or null to remove the flag
    • getDragType

      public static HeaderDragType getDragType(Node child)
      Deprecated.
      Gets the value of the dragType property of the specified child.
      Parameters:
      child - the child node
      Returns:
      the HeaderDragType, or null if not set
    • dragTypeProperty

      public static ObjectProperty<HeaderDragType> dragTypeProperty(Node child)
      Deprecated.
      Specifies the HeaderDragType of the child, indicating whether it is a draggable part of the HeaderBar. A value of null indicates that the drag type is not set.
      Default value:
      null
      Parameters:
      child - the child node
      Returns:
      the dragType property
      Since:
      26
    • setButtonType

      public static void setButtonType(Node child, HeaderButtonType value)
      Deprecated.
      Sets the value of the buttonType property for the specified child.
      Parameters:
      child - the child node
      value - the HeaderButtonType, or null
    • getButtonType

      public static HeaderButtonType getButtonType(Node child)
      Deprecated.
      Gets the value of the buttonType property of the specified child.
      Parameters:
      child - the child node
      Returns:
      the HeaderButtonType, or null
    • buttonTypeProperty

      public static ObjectProperty<HeaderButtonType> buttonTypeProperty(Node child)
      Deprecated.
      Specifies the HeaderButtonType of the child, indicating its semantic use in the header bar.

      This property can be set on any Node. Specifying a header button type also provides the behavior associated with the button type. If the default behavior is not desired, applications can register an event filter on the child node that consumes the MouseEvent.MOUSE_RELEASED event.

      Default value:
      null
      Parameters:
      child - the child node
      Returns:
      the buttonType property
      Since:
      26
    • setPrefButtonHeight

      public static void setPrefButtonHeight(Stage stage, double height)
      Deprecated.
      Sets the value of the prefButtonHeight property for the specified Stage.
      Parameters:
      stage - the Stage
      height - the preferred height, or 0 to hide the system-provided header buttons
    • getPrefButtonHeight

      public static double getPrefButtonHeight(Stage stage)
      Deprecated.
      Gets the value of the prefButtonHeight property of the specified Stage.
      Parameters:
      stage - the Stage
      Returns:
      the preferred height of the system-provided header buttons
    • prefButtonHeightProperty

      public static DoubleProperty prefButtonHeightProperty(Stage stage)
      Deprecated.
      Specifies the preferred height of the system-provided header buttons of the specified Stage.

      Any value except zero and USE_DEFAULT_SIZE is only a hint for the platform window toolkit. The platform might accommodate the preferred height in various ways, such as by stretching the header buttons (fully or partially) to fill the preferred height, or centering the header buttons (fully or partially) within the preferred height. Some platforms might only accommodate the preferred height within platform-specific constraints, or ignore it entirely.

      Setting the preferred height to zero hides the system-provided header buttons, allowing applications to use custom header buttons instead (see setButtonType(Node, HeaderButtonType)).

      The default value USE_DEFAULT_SIZE indicates that the platform should choose the button height.

      Default value:
      USE_DEFAULT_SIZE
      Parameters:
      stage - the Stage
      Returns:
      the prefButtonHeight property
      Since:
      26
    • leftSystemInsetProperty

      public static ReadOnlyObjectProperty<Dimension2D> leftSystemInsetProperty(Stage stage)
      Deprecated.
      Describes the size of the left system-reserved inset of the specified Stage, which is an area reserved for the iconify, maximize, and close window buttons. If there are no window buttons on the left side of the window, the returned area is an empty Dimension2D.
      Parameters:
      stage - the Stage
      Returns:
      the leftSystemInset property
      Since:
      26
    • getLeftSystemInset

      public static Dimension2D getLeftSystemInset(Stage stage)
      Deprecated.
      Gets the value of the leftSystemInset property of the specified Stage.
      Parameters:
      stage - the Stage
      Returns:
      the size of the left system-reserved inset
      Since:
      26
    • rightSystemInsetProperty

      public static ReadOnlyObjectProperty<Dimension2D> rightSystemInsetProperty(Stage stage)
      Deprecated.
      Describes the size of the right system-reserved inset of the specified Stage, which is an area reserved for the iconify, maximize, and close window buttons. If there are no window buttons on the right side of the window, the returned area is an empty Dimension2D.
      Parameters:
      stage - the Stage
      Returns:
      the rightSystemInset property
      Since:
      26
    • getRightSystemInset

      public static Dimension2D getRightSystemInset(Stage stage)
      Deprecated.
      Gets the value of the rightSystemInset property of the specified Stage.
      Parameters:
      stage - the Stage
      Returns:
      the size of the right system-reserved inset
      Since:
      26
    • minSystemHeightProperty

      public static ReadOnlyDoubleProperty minSystemHeightProperty(Stage stage)
      Deprecated.
      The system-provided minimum recommended height for the HeaderBar of the specified Stage, which usually corresponds to the height of the default header buttons. Applications can use this value as a sensible lower limit for the height of the HeaderBar.

      By default, HeaderBar.minHeight is set to the value of minSystemHeight, unless minHeight is explicitly set by a stylesheet or application code.

      Parameters:
      stage - the Stage
      Returns:
      the minSystemHeight property
      Since:
      26
    • getMinSystemHeight

      public static double getMinSystemHeight(Stage stage)
      Deprecated.
      Gets the value of the minSystemHeight property of the specified Stage.
      Parameters:
      stage - the Stage
      Returns:
      the system-provided minimum recommended height for the HeaderBar
      Since:
      26
    • setAlignment

      public static void setAlignment(Node child, Pos value)
      Deprecated.
      Sets the alignment for the child when contained in a HeaderBar. If set, will override the header bar's default alignment for the child's position. Setting the value to null will remove the constraint.
      Parameters:
      child - the child node
      value - the alignment position
    • getAlignment

      public static Pos getAlignment(Node child)
      Deprecated.
      Returns the child's alignment in the HeaderBar.
      Parameters:
      child - the child node
      Returns:
      the alignment position for the child, or null if no alignment was set
    • setMargin

      public static void setMargin(Node child, Insets value)
      Deprecated.
      Sets the margin for the child when contained in a HeaderBar. If set, the header bar will lay it out with the margin space around it. Setting the value to null will remove the constraint.
      Parameters:
      child - the child node
      value - the margin of space around the child
    • getMargin

      public static Insets getMargin(Node child)
      Deprecated.
      Returns the child's margin.
      Parameters:
      child - the child node
      Returns:
      the margin for the child, or null if no margin was set
    • leftProperty

      public final ObjectProperty<Node> leftProperty()
      Deprecated.
      The left area of the HeaderBar.
      Default value:
      null
      Returns:
      the left property
      Since:
      26
      See Also:
    • getLeft

      public final Node getLeft()
      Deprecated.
      Gets the value of the left property.
      Property description:
      The left area of the HeaderBar.
      Default value:
      null
      Returns:
      the value of the left property
      Since:
      26
      See Also:
    • setLeft

      public final void setLeft(Node value)
      Deprecated.
      Sets the value of the left property.
      Property description:
      The left area of the HeaderBar.
      Default value:
      null
      Parameters:
      value - the value for the left property
      Since:
      26
      See Also:
    • centerProperty

      public final ObjectProperty<Node> centerProperty()
      Deprecated.
      The center area of the HeaderBar.
      Default value:
      null
      Returns:
      the center property
      See Also:
    • getCenter

      public final Node getCenter()
      Deprecated.
      Gets the value of the center property.
      Property description:
      The center area of the HeaderBar.
      Default value:
      null
      Returns:
      the value of the center property
      See Also:
    • setCenter

      public final void setCenter(Node value)
      Deprecated.
      Sets the value of the center property.
      Property description:
      The center area of the HeaderBar.
      Default value:
      null
      Parameters:
      value - the value for the center property
      See Also:
    • rightProperty

      public final ObjectProperty<Node> rightProperty()
      Deprecated.
      The right area of the HeaderBar.
      Default value:
      null
      Returns:
      the right property
      Since:
      26
      See Also:
    • getRight

      public final Node getRight()
      Deprecated.
      Gets the value of the right property.
      Property description:
      The right area of the HeaderBar.
      Default value:
      null
      Returns:
      the value of the right property
      Since:
      26
      See Also:
    • setRight

      public final void setRight(Node value)
      Deprecated.
      Sets the value of the right property.
      Property description:
      The right area of the HeaderBar.
      Default value:
      null
      Parameters:
      value - the value for the right property
      Since:
      26
      See Also:
    • leftSystemPaddingProperty

      public final BooleanProperty leftSystemPaddingProperty()
      Deprecated.
      Specifies whether additional padding should be added to the left side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the left side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Returns:
      the leftSystemPadding property
      Since:
      26
      See Also:
    • isLeftSystemPadding

      public final boolean isLeftSystemPadding()
      Deprecated.
      Gets the value of the leftSystemPadding property.
      Property description:
      Specifies whether additional padding should be added to the left side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the left side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Returns:
      the value of the leftSystemPadding property
      Since:
      26
      See Also:
    • setLeftSystemPadding

      public final void setLeftSystemPadding(boolean value)
      Deprecated.
      Sets the value of the leftSystemPadding property.
      Property description:
      Specifies whether additional padding should be added to the left side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the left side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Parameters:
      value - the value for the leftSystemPadding property
      Since:
      26
      See Also:
    • rightSystemPaddingProperty

      public final BooleanProperty rightSystemPaddingProperty()
      Deprecated.
      Specifies whether additional padding should be added to the right side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the right side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Returns:
      the rightSystemPadding property
      Since:
      26
      See Also:
    • isRightSystemPadding

      public final boolean isRightSystemPadding()
      Deprecated.
      Gets the value of the rightSystemPadding property.
      Property description:
      Specifies whether additional padding should be added to the right side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the right side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Returns:
      the value of the rightSystemPadding property
      Since:
      26
      See Also:
    • setRightSystemPadding

      public final void setRightSystemPadding(boolean value)
      Deprecated.
      Sets the value of the rightSystemPadding property.
      Property description:
      Specifies whether additional padding should be added to the right side of the HeaderBar. The size of the additional padding corresponds to the size of the system-reserved area that contains the default header buttons (iconify, maximize, and close). If the system-reserved area contains no header buttons, no additional padding is added to the right side of the HeaderBar.

      Applications that use a single HeaderBar extending the entire width of the window should set this property to true to prevent the header buttons from overlapping the content of the HeaderBar.

      Default value:
      true
      Parameters:
      value - the value for the rightSystemPadding property
      Since:
      26
      See Also: