Class ToolBar

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable

    @DefaultProperty("items")
    public class ToolBar
    extends Control

    A ToolBar is a control which displays items horizontally or vertically. The most common items to place within a ToolBar are Buttons, ToggleButtons and Separators, but you are not restricted to just these, and can insert any Node into them.

    If there are too many items to fit in the ToolBar an overflow button will appear. The overflow button allows you to select items that are not currently visible in the toolbar.

    ToolBar sets focusTraversable to false.

    Example of a horizontal ToolBar with eight buttons separated with two vertical separators.

    
     ToolBar toolBar = new ToolBar(
         new Button("New"),
         new Button("Open"),
         new Button("Save"),
         new Separator(true),
         new Button("Clean"),
         new Button("Compile"),
         new Button("Run"),
         new Separator(true),
         new Button("Debug"),
         new Button("Profile")
     );
     
    Since:
    JavaFX 2.0
    • Constructor Detail

      • ToolBar

        public ToolBar()
        Creates an empty tool bar.
      • ToolBar

        public ToolBar​(Node... items)
        Creates a tool bar populated with the specified nodes. None of the items can be null.
        Parameters:
        items - the items to add
    • Method Detail

      • getItems

        public final ObservableList<Node> getItems()
        The items contained in the ToolBar. Typical use case for a ToolBar suggest that the most common items to place within it are Buttons, ToggleButtons, and Separators, but you are not restricted to just these, and can insert any Node. The items added must not be null.
        Returns:
        the list of items
      • setOrientation

        public final void setOrientation​(Orientation value)
        Sets the value of the property orientation.
        Property description:
        The orientation of the ToolBar - this can either be horizontal or vertical.
      • getOrientation

        public final Orientation getOrientation()
        Gets the value of the property orientation.
        Property description:
        The orientation of the ToolBar - this can either be horizontal or vertical.
      • createDefaultSkin

        protected Skin<?> createDefaultSkin()
        Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).
        Overrides:
        createDefaultSkin in class Control
        Returns:
        new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
      • 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
      • getInitialFocusTraversable

        protected Boolean getInitialFocusTraversable()
        Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. This method is overridden as by default UI controls have focus traversable set to true, but that is not appropriate for this control.
        Overrides:
        getInitialFocusTraversable in class Control
        Returns:
        the initial focus traversable state of this control
        Since:
        9