horizontalMenu

The horizontalMenu component is used to display a horizontal menu with hierarchical drop-down sub-menus.

horizontalMenu is used in the Main view with top menu template in the View Creation Wizard. If you want to use the new view instead of the existing main view, select the Use as default main view checkbox on the first step of the wizard. Then Studio will replace the layout attribute of the @Route annotation in all views and set the new view in the jmix.ui.main-view-id application property.

It can also be used on any view as any other visual component.

  • XML element: horizontalMenu

  • Java class: HorizontalMenu

Basics

To add the component on a view, place it in the view descriptor:

<horizontalMenu id="horizontalMenu" width="100%"/>
horizontal menu

You can also create and add the component to a view in a Java controller:

@Autowired
private UiComponents uiComponents;
@Autowired
private ApplicationContext applicationContext;
@ViewComponent
private VerticalLayout navigation;

@Subscribe
public void onInit(final InitEvent event) {
    HorizontalMenu horizontalMenu = uiComponents.create(HorizontalMenu.class);

    MenuConfigHorizontalMenuItemProvider itemProvider =
            applicationContext.getBean(MenuConfigHorizontalMenuItemProvider.class);
    horizontalMenu.setMenuItemProvider(itemProvider);
    navigation.add(horizontalMenu);

    itemProvider.load();
}

Attributes

loadMenuConfig

The loadMenuConfig attribute is used to control the loading of menu structure from Menu Configuration. The default value is true, which means that the horizontalMenu component loads its menu structure from MenuConfig by default. If you want to use a different item provider, you should set the loadMenuConfig attribute to false first.

Handlers

To generate a handler stub in Jmix Studio, use the Handlers tab of the Jmix UI inspector panel or the Generate Handler action available in the top panel of the view class and through the CodeGenerate menu (Alt+Insert / Cmd+N).