Class FMenuBar

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.menubar.MenuBar
com.vaadin.featurepack.ui.FMenuBar
All Implemented Interfaces:
ClientConnector, FAbstractClientConnector, FSizeable, HasSizeable, FAbstractComponent, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<FMenuBar>, com.vaadin.flow.component.contextmenu.HasMenuItems, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<FMenuBar>, com.vaadin.flow.component.FocusNotifier<FMenuBar>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.menubar.MenuBarVariant>, Serializable

@JsModule("./menu-bar-styles.js") public class FMenuBar extends com.vaadin.flow.component.menubar.MenuBar implements FAbstractComponent, com.vaadin.flow.component.Focusable<FMenuBar>, HasSizeable

A class representing a Vaadin 7/8 horizontal menu bar. The menu can contain MenuItem objects, which in turn can contain more MenuBars. These sub-level MenuBars are represented as vertical menu.

See Also:
  • Constructor Details

    • FMenuBar

      public FMenuBar()
  • Method Details

    • fireEvent

      protected void fireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent)
      Overrides:
      fireEvent in class com.vaadin.flow.component.Component
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • beforeClientResponse

      public void beforeClientResponse(boolean initial)
      Description copied from interface: ClientConnector
      Called before the response is written to client side. Gives the legacy connector an opportunity to set computed/dynamic state values.

      This is implemented for the legacy components to keep consistent behavior and e.g. legaze size calculations working.

      NOTE: the parameter initial is false when the component is attached again to a new UI when PreserveOnRefresh is used.

      Specified by:
      beforeClientResponse in interface ClientConnector
      Specified by:
      beforeClientResponse in interface FAbstractClientConnector
      Specified by:
      beforeClientResponse in interface FAbstractComponent
      Parameters:
      initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.
    • setLabelComponent

      public void setLabelComponent(com.vaadin.flow.component.Component labelComponent)
      Description copied from interface: FAbstractComponent
      Sets the component's label component. Flow components that support caption component usually overrides this.
      Specified by:
      setLabelComponent in interface FAbstractComponent
      Parameters:
      labelComponent - the new label component for the component.
    • addItem

      public FMenuBar.MenuItem addItem(String caption, FMenuBar.Command command)
      Add a new item to the menu bar. Command can be null, but a caption must be given.
      Parameters:
      caption - the text for the menu item
      command - the command for the menu item
      Throws:
      IllegalArgumentException
    • addItem

      public FMenuBar.MenuItem addItem(String caption, com.vaadin.flow.component.icon.Icon icon, FMenuBar.Command command)
      Add a new item to the menu bar. Icon and command can be null, but a caption must be given.
      Parameters:
      caption - the text for the menu item
      icon - the icon component for the menu item
      command - the command for the menu item
      Throws:
      IllegalArgumentException
    • addItem

      public FMenuBar.MenuItem addItem(String caption, Resource icon, FMenuBar.Command command)
      Add a new item to the menu bar. Icon and command can be null, but a caption must be given.
      Parameters:
      caption - the text for the menu item
      icon - the icon for the menu item
      command - the command for the menu item
      Throws:
      IllegalArgumentException
    • addItemBefore

      public FMenuBar.MenuItem addItemBefore(String caption, Resource icon, FMenuBar.Command command, FMenuBar.MenuItem itemToAddBefore)
      Add an item before some item. If the given item does not exist the item is added at the end of the menu. Icon and command can be null, but a caption must be given.
      Parameters:
      caption - the text for the menu item
      icon - the icon for the menu item
      command - the command for the menu item
      itemToAddBefore - the item that will be after the new item
      Throws:
      IllegalArgumentException
    • getFItems

      public List<FMenuBar.MenuItem> getFItems()
      Returns a list with all the MenuItem objects in the menu bar
      Returns:
      a list containing the MenuItem objects in the menu bar
    • removeItem

      public void removeItem(FMenuBar.MenuItem item)
      Remove first occurrence the specified item from the main menu
      Parameters:
      item - The item to be removed
    • removeItems

      public void removeItems()
      Empty the menu bar
    • getSize

      public int getSize()
      Returns the size of the menu.
      Returns:
      The size of the menu
    • setMoreMenuItem

      public void setMoreMenuItem(FMenuBar.MenuItem item)
      Set the item that is used when collapsing the top level menu. All "overflowing" items will be added below this. The item command will be ignored. If set to null, the default item with a downwards arrow is used. The item command (if specified) is ignored.
      Parameters:
      item -
    • getMoreMenuItem

      public FMenuBar.MenuItem getMoreMenuItem()
      Get the MenuItem used as the collapse menu item.
      Returns:
    • setAutoOpen

      public void setAutoOpen(boolean autoOpenTopLevelMenu)
      Using this method menubar can be put into a special mode where top level menus opens without clicking on the menu, but automatically when mouse cursor is moved over the menu. In this mode the menu also closes itself if the mouse is moved out of the opened menu.

      Note, that on touch devices the menu still opens on a click event.

      Parameters:
      autoOpenTopLevelMenu - true if menus should be opened without click, the default is false
    • isAutoOpen

      public boolean isAutoOpen()
      Detects whether the menubar is in a mode where top level menus are automatically opened when the mouse cursor is moved over the menu. Normally root menu opens only by clicking on the menu. Submenus always open automatically.
      Returns:
      true if the root menus open without click, the default is false
    • setHtmlContentAllowed

      public void setHtmlContentAllowed(boolean htmlContentAllowed)
      Sets whether html is allowed in the item captions. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text.
      Parameters:
      htmlContentAllowed - true if the captions are used as html, false if used as plain text
    • isHtmlContentAllowed

      public boolean isHtmlContentAllowed()
      Checks whether item captions are interpreted as html or plain text.
      Returns:
      true if the captions are used as html, false if used as plain text
      See Also: