/* * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.scene.control; import javafx.css.converter.BooleanConverter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javafx.beans.DefaultProperty; import javafx.beans.property.BooleanProperty; import javafx.beans.value.ObservableValue; import javafx.beans.value.WritableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.css.CssMetaData; import javafx.css.StyleableBooleanProperty; import javafx.scene.control.skin.MenuBarSkin; import javafx.css.Styleable; import javafx.css.StyleableProperty; import javafx.scene.AccessibleRole; /** *
* A MenuBar control traditionally is placed at the very top of the user * interface, and embedded within it are {@link Menu Menus}. To add a menu to * a menubar, you add it to the {@link #getMenus() menus} ObservableList. * By default, for each menu added to the menubar, it will be * represented as a button with the Menu {@link MenuItem#textProperty() text} value displayed. *
* MenuBar sets focusTraversable to false. *
* * To create and populate a {@code MenuBar}, you may do what is shown below. * Please refer to the {@link 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);
*
*
* @see Menu
* @see MenuItem
* @since JavaFX 2.0
*/
@DefaultProperty("menus")
public class MenuBar extends Control {
/***************************************************************************
* *
* Constructors *
* *
**************************************************************************/
/**
* Creates a new empty MenuBar.
*/
public MenuBar() {
this((Menu[])null);
}
/**
* Creates a new MenuBar populated with the given menus.
*
* @param menus The menus to place inside the MenuBar
* @since JavaFX 8u40
*/
public MenuBar(Menu... menus) {
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
setAccessibleRole(AccessibleRole.MENU_BAR);
if (menus != null) {
getMenus().addAll(menus);
}
// focusTraversable is styleable through css. Calling setFocusTraversable
// makes it look to css like the user set the value and css will not
// override. Initializing focusTraversable by calling applyStyle with null
// StyleOrigin ensures that css will be able to override the value.
((StyleableProperty