Class MenuBar

    • 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 new MenuItem component with the provided text content and adds it to the root level of this menu bar.

        The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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 MenuItem component
      • addItem

        public MenuItem addItem​(Component component)
        Creates a new MenuItem component and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

        The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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 MenuItem component
      • addItem

        public MenuItem addItem​(String text,
                                String tooltipText)
        Creates a new MenuItem component with the provided text content and the tooltip text and adds it to the root level of this menu bar.

        The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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
        tooltipText - the tooltip text for the new item
        Returns:
        the added MenuItem component
      • addItem

        public MenuItem addItem​(Component component,
                                String tooltipText)
        Creates a new MenuItem component with the provided tooltip text and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

        The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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
        tooltipText - the tooltip text for the new item
        Returns:
        the added MenuItem component
      • addItem

        public MenuItem addItem​(String text,
                                String tooltipText,
                                ComponentEventListener<ClickEvent<MenuItem>> clickListener)
        Creates a new MenuItem component 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 MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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
        tooltipText - the tooltip text for the new item
        clickListener - the handler for clicking the new item, can be null to not add listener
        Returns:
        the added MenuItem component
      • addItem

        public MenuItem addItem​(Component component,
                                String tooltipText,
                                ComponentEventListener<ClickEvent<MenuItem>> clickListener)
        Creates a new MenuItem component 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 created MenuItem.

        The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is 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 item
        tooltipText - the tooltip text for the new item
        clickListener - the handler for clicking the new item, can be null to not add listener
        Returns:
        the added MenuItem component
      • remove

        public void remove​(MenuItem... items)
        Removes the given item components from this menu bar.
        Parameters:
        items - the item components to remove, not null
        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:
        getChildren in class Component
        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 - true to make the sub menus open on hover (mouseover), false to 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:
        true if the sub menus open by hovering on the root level buttons, false if 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, not null
      • onAttach

        protected void onAttach​(AttachEvent attachEvent)
        Description copied from class: Component
        Called when the component is attached to a UI.

        The default implementation does nothing.

        This method is invoked before the AttachEvent is fired for the component.

        Overrides:
        onAttach in class Component
        Parameters:
        attachEvent - the attach event