Class MenuBar

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable

    @DefaultProperty("menus")
    public class MenuBar
    extends Control

    A MenuBar control traditionally is placed at the very top of the user interface, and embedded within it are Menus. To add a menu to a menubar, you add it to the menus ObservableList. By default, for each menu added to the menubar, it will be represented as a button with the Menu text value displayed.

    MenuBar sets focusTraversable to false.

    To create and populate a MenuBar, you may do what is shown below. Please refer to the Menu API page for more information on how to configure it.
    
     final Menu menu1 = new Menu("File");
     final Menu menu2 = new Menu("Options");
     final Menu menu3 = new Menu("Help");
    
     MenuBar menuBar = new MenuBar();
     menuBar.getMenus().addAll(menu1, menu2, menu3);
     
    Since:
    JavaFX 2.0
    See Also:
    Menu, MenuItem
    • Property Detail

      • useSystemMenuBar

        public final BooleanProperty useSystemMenuBarProperty
        Use the system menu bar if the current platform supports it. This should not be set on more than one MenuBar instance per Stage. If this property is set to true on more than one MenuBar in the same Stage, then the last menu set is allowed to modify the system menu bar, and if there is an existing installed system menu it is unset and removed from the system menu bar. Note that trying to uni-directionally bind to this property will throw a RuntimeException. Please use bi-directional binding to this property instead.
        Since:
        JavaFX 2.1
        See Also:
        isUseSystemMenuBar(), setUseSystemMenuBar(boolean)
    • Constructor Detail

      • MenuBar

        public MenuBar()
        Creates a new empty MenuBar.
      • MenuBar

        public MenuBar​(Menu... menus)
        Creates a new MenuBar populated with the given menus.
        Parameters:
        menus - The menus to place inside the MenuBar
        Since:
        JavaFX 8u40
    • Method Detail

      • useSystemMenuBarProperty

        public final BooleanProperty useSystemMenuBarProperty()
        Use the system menu bar if the current platform supports it. This should not be set on more than one MenuBar instance per Stage. If this property is set to true on more than one MenuBar in the same Stage, then the last menu set is allowed to modify the system menu bar, and if there is an existing installed system menu it is unset and removed from the system menu bar. Note that trying to uni-directionally bind to this property will throw a RuntimeException. Please use bi-directional binding to this property instead.
        Since:
        JavaFX 2.1
        See Also:
        isUseSystemMenuBar(), setUseSystemMenuBar(boolean)
      • setUseSystemMenuBar

        public final void setUseSystemMenuBar​(boolean value)
        Sets the value of the property useSystemMenuBar.
        Property description:
        Use the system menu bar if the current platform supports it. This should not be set on more than one MenuBar instance per Stage. If this property is set to true on more than one MenuBar in the same Stage, then the last menu set is allowed to modify the system menu bar, and if there is an existing installed system menu it is unset and removed from the system menu bar. Note that trying to uni-directionally bind to this property will throw a RuntimeException. Please use bi-directional binding to this property instead.
        Since:
        JavaFX 2.1
      • isUseSystemMenuBar

        public final boolean isUseSystemMenuBar()
        Gets the value of the property useSystemMenuBar.
        Property description:
        Use the system menu bar if the current platform supports it. This should not be set on more than one MenuBar instance per Stage. If this property is set to true on more than one MenuBar in the same Stage, then the last menu set is allowed to modify the system menu bar, and if there is an existing installed system menu it is unset and removed from the system menu bar. Note that trying to uni-directionally bind to this property will throw a RuntimeException. Please use bi-directional binding to this property instead.
        Since:
        JavaFX 2.1
      • getMenus

        public final ObservableList<Menu> getMenus()
        The menus to show within this MenuBar. If this ObservableList is modified at runtime, the MenuBar will update as expected.
        Returns:
        the list of menus to show within this MenuBar
        See Also:
        Menu
      • 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