Class MenuBar
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.menubar.MenuBar
-
- All Implemented Interfaces:
AttachNotifier,HasMenuItems,DetachNotifier,HasElement,HasEnabled,HasSize,HasStyle,HasTheme,Serializable
@Tag("vaadin-menu-bar") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="23.3.30") @NpmPackage(value="@vaadin/menu-bar",version="23.3.30") @NpmPackage(value="@vaadin/vaadin-menu-bar",version="23.3.30") @NpmPackage(value="@vaadin/tooltip",version="23.3.30") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("./menubarConnector.js") @JsModule("@vaadin/menu-bar/src/vaadin-menu-bar.js") @JsModule("@vaadin/tooltip/src/vaadin-tooltip.js") public class MenuBar extends Component implements HasMenuItems, HasSize, HasStyle, HasTheme, HasEnabled
Menu Bar is a horizontal button bar with hierarchical drop-down menus. Menu items can either trigger an action, open a menu, or work as a toggle.- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMenuBar.MenuBarI18nThe internationalization properties forMenuBar
-
Constructor Summary
Constructors Constructor Description MenuBar()Creates an empty menu bar component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MenuItemaddItem(Component component)Creates a newMenuItemcomponent and adds it to the root level of this menu bar.MenuItemaddItem(Component component, ComponentEventListener<ClickEvent<MenuItem>> clickListener)Creates a newMenuItemcomponent with the provided click listener and adds it to the root level of this menu bar.MenuItemaddItem(Component component, String tooltipText)Creates a newMenuItemcomponent with the provided tooltip text and adds it to the root level of this menu bar.MenuItemaddItem(Component component, String tooltipText, ComponentEventListener<ClickEvent<MenuItem>> clickListener)Creates a newMenuItemcomponent with the provided click listener and the tooltip text and adds it to the root level of this menu bar.MenuItemaddItem(String text)Creates a newMenuItemcomponent with the provided text content and adds it to the root level of this menu bar.MenuItemaddItem(String text, ComponentEventListener<ClickEvent<MenuItem>> clickListener)Creates a newMenuItemcomponent with the provided text content and click listener and adds it to the root level of this menu bar.MenuItemaddItem(String text, String tooltipText)Creates a newMenuItemcomponent with the provided text content and the tooltip text and adds it to the root level of this menu bar.MenuItemaddItem(String text, String tooltipText, ComponentEventListener<ClickEvent<MenuItem>> clickListener)Creates a newMenuItemcomponent with the provided text content and the tooltip text and click listener and adds it to the root level of this menu bar.voidaddThemeVariants(MenuBarVariant... variants)Adds theme variants to the component.Stream<Component>getChildren()Gets the child components of this menu bar.MenuBar.MenuBarI18ngetI18n()Gets the internationalization object previously set for this component.List<MenuItem>getItems()Gets theMenuItemcomponents added to the root level of the menu bar.booleanisOpenOnHover()Gets whether the sub menus open by clicking or hovering on the root level buttons.protected voidonAttach(AttachEvent attachEvent)Called when the component is attached to a UI.voidremove(MenuItem... items)Removes the given item components from this menu bar.voidremoveAll()Removes all item components from this menu bar.voidremoveThemeVariants(MenuBarVariant... variants)Removes theme variants from the component.voidsetI18n(MenuBar.MenuBarI18n i18n)Sets the internationalization properties for this component.voidsetOpenOnHover(boolean openOnHover)Sets the event which opens the sub menus of the root level buttons.voidsetTooltipText(MenuItem item, String tooltipText)Sets the tooltip text for the givenMenuItem.-
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
-
-
-
Constructor Detail
-
MenuBar
public MenuBar()
Creates an empty menu bar component.Use
addItem(String)to add content to the menu bar.
-
-
Method Detail
-
addItem
public MenuItem addItem(String text)
Creates a newMenuItemcomponent with the provided text content and adds it to the root level of this menu bar.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
text- the text content for the new item- Returns:
- the added
MenuItemcomponent
-
addItem
public MenuItem addItem(Component component)
Creates a newMenuItemcomponent and adds it to the root level of this menu bar. The provided component is added into the createdMenuItem.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
component- the component to add inside new item- Returns:
- the added
MenuItemcomponent
-
addItem
public MenuItem addItem(String text, ComponentEventListener<ClickEvent<MenuItem>> clickListener)
Creates a newMenuItemcomponent with the provided text content and click listener and adds it to the root level of this menu bar.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Specified by:
addItemin interfaceHasMenuItems- Parameters:
text- the text content for the new itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent - See Also:
HasMenuItems.addItem(Component, ComponentEventListener),ContextMenuBase.add(Component...),SubMenuBase.add(Component...)
-
addItem
public MenuItem addItem(Component component, ComponentEventListener<ClickEvent<MenuItem>> clickListener)
Creates a newMenuItemcomponent with the provided click listener and adds it to the root level of this menu bar. The provided component is added into the createdMenuItem.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Specified by:
addItemin interfaceHasMenuItems- Parameters:
component- the component to add inside the added menu itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent - See Also:
HasMenuItems.addItem(String, ComponentEventListener),ContextMenuBase.add(Component...),SubMenuBase.add(Component...)
-
addItem
public MenuItem addItem(String text, String tooltipText)
Creates a newMenuItemcomponent with the provided text content and the tooltip text and adds it to the root level of this menu bar.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
text- the text content for the new itemtooltipText- the tooltip text for the new item- Returns:
- the added
MenuItemcomponent
-
addItem
public MenuItem addItem(Component component, String tooltipText)
Creates a newMenuItemcomponent with the provided tooltip text and adds it to the root level of this menu bar. The provided component is added into the createdMenuItem.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
component- the component to add inside new itemtooltipText- the tooltip text for the new item- Returns:
- the added
MenuItemcomponent
-
addItem
public MenuItem addItem(String text, String tooltipText, ComponentEventListener<ClickEvent<MenuItem>> clickListener)
Creates a newMenuItemcomponent with the provided text content and the tooltip text and click listener and adds it to the root level of this menu bar.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
text- the text content for the new itemtooltipText- the tooltip text for the new itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent
-
addItem
public MenuItem addItem(Component component, String tooltipText, ComponentEventListener<ClickEvent<MenuItem>> clickListener)
Creates a newMenuItemcomponent with the provided click listener and the tooltip text and adds it to the root level of this menu bar. The provided component is added into the createdMenuItem.The added
MenuItemcomponent is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, theMenuItemis moved out of the button, into a context menu openable via an overflow button at the end of the button row.To add content to the sub menu opened by clicking the root level item, use
MenuItemBase.getSubMenu().- Parameters:
component- the component to add inside the added menu itemtooltipText- the tooltip text for the new itemclickListener- the handler for clicking the new item, can benullto not add listener- Returns:
- the added
MenuItemcomponent
-
getItems
public List<MenuItem> getItems()
Gets theMenuItemcomponents added to the root level of the menu bar.To manage the contents inside the sub menus, use the
MenuItemBase.getSubMenu().- Returns:
- the root level
MenuItemcomponents added to this menu bar
-
remove
public void remove(MenuItem... items)
Removes the given item components from this menu bar.- Parameters:
items- the item components to remove, notnull- Throws:
IllegalArgumentException- if any of the item components to remove is not a child of this menu bar
-
removeAll
public void removeAll()
Removes all item components from this menu bar.
-
getChildren
public Stream<Component> getChildren()
Gets the child components of this menu bar.The returned components are the same as the ones returned by
getItems().- Overrides:
getChildrenin classComponent- Returns:
- the child components of this menu bar
- See Also:
Id
-
setOpenOnHover
public void setOpenOnHover(boolean openOnHover)
Sets the event which opens the sub menus of the root level buttons.- Parameters:
openOnHover-trueto make the sub menus open on hover (mouseover),falseto make them openable by clicking
-
isOpenOnHover
public boolean isOpenOnHover()
Gets whether the sub menus open by clicking or hovering on the root level buttons.- Returns:
trueif the sub menus open by hovering on the root level buttons,falseif they open by clicking
-
addThemeVariants
public void addThemeVariants(MenuBarVariant... variants)
Adds theme variants to the component.- Parameters:
variants- theme variants to add
-
removeThemeVariants
public void removeThemeVariants(MenuBarVariant... variants)
Removes theme variants from the component.- Parameters:
variants- theme variants to remove
-
getI18n
public MenuBar.MenuBarI18n getI18n()
Gets the internationalization object previously set for this component.Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using
setI18n(MenuBarI18n)- Returns:
- the i18n object. It will be
null, If the i18n properties weren't set.
-
setI18n
public void setI18n(MenuBar.MenuBarI18n i18n)
Sets the internationalization properties for this component.- Parameters:
i18n- the internationalized properties, notnull
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:ComponentCalled when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEventis fired for the component.
-
-