Class MenuBar
- All Implemented Interfaces:
AttachNotifier,HasMenuItems,DetachNotifier,HasElement,HasEnabled,HasSize,HasStyle,HasTheme,HasThemeVariant<MenuBarVariant>,Serializable
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a newMenuItemcomponent and adds it to the root level of this menu bar.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.Creates a newMenuItemcomponent with the provided tooltip text and adds it to the root level of this menu bar.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.Creates a newMenuItemcomponent with the provided text content and adds it to the root level of this menu bar.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.Creates a newMenuItemcomponent with the provided text content and the tooltip text and adds it to the root level of this menu bar.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.voidclose()Closes the current submenu.Gets the child components of this menu bar.getI18n()Gets the internationalization object previously set for this component.getItems()Gets theMenuItemcomponents added to the root level of the menu bar.booleanGets whether the sub menus open by clicking or hovering on the root level buttons.booleanGets whether the menu bar uses reverse collapse order.booleanGets whether the menu bar uses tab navigation.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidRemoves the given item components from this menu bar.voidRemoves all item components from this menu bar.voidsetI18n(MenuBar.MenuBarI18n i18n) Sets the internationalization object for this component.voidsetOpenOnHover(boolean openOnHover) Sets the event which opens the sub menus of the root level buttons.voidsetReverseCollapseOrder(boolean reverseCollapseOrder) Sets reverse collapse order for the menu bar.voidsetTabNavigation(boolean tabNavigation) Sets tab navigation for the menu bar.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, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
-
Constructor Details
-
MenuBar
public MenuBar()Creates an empty menu bar component.Use
addItem(String)to add content to the menu bar.
-
-
Method Details
-
addItem
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
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
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:
-
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:
-
addItem
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
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
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
-
removeAll
public void removeAll()Removes all item components from this menu bar. -
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:
-
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
-
setReverseCollapseOrder
public void setReverseCollapseOrder(boolean reverseCollapseOrder) Sets reverse collapse order for the menu bar.- Parameters:
reverseCollapseOrder- Iftrue, the buttons will be collapsed into the overflow menu starting from the "start" end of the bar instead of the "end".
-
isReverseCollapseOrder
public boolean isReverseCollapseOrder()Gets whether the menu bar uses reverse collapse order.- Returns:
trueif the buttons will be collapsed into the overflow menu starting from the "start" end of the bar instead of the "end".
-
getI18n
Gets the internationalization object previously set for this component.NOTE: Updating the instance that is returned from this method will not update the component if not set again using
setI18n(MenuBarI18n)- Returns:
- the i18n object or
nullif no i18n object has been set
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method. -
close
public void close()Closes the current submenu.
-