A menu widget provides a list of items which are associated with some contents. At any time one item is selected from the list.

A WMenu works in conjunction with a WStackedWidget, which manages the contents.

The panel at the left is implemented using a WMenu.

Example
source
  void Menu() {
    WContainerWidget container = new WContainerWidget();
    WStackedWidget contents = new WStackedWidget();
    WMenu menu = new WMenu(contents, (WContainerWidget) container);
    menu.setStyleClass("nav nav-pills flex-column");
    menu.setWidth(new WLength(150));
    menu.addItem("Internal paths", new WTextArea("Internal paths contents"));
    menu.addItem("Anchor", new WTextArea("Anchor contents"));
    menu.addItem("Stacked widget", new WTextArea("Stacked widget contents"));
    menu.addItem("Tab widget", new WTextArea("Tab widget contents"));
    menu.addItem("Menu", new WTextArea("Menu contents"));
    container.addWidget(contents);
  }

You can create items with submenus by using the WSubMenuItem rather than the default WMenuItem.

A menu has full support for bookmarks and the back button, by rendering its items using WAnchor and making use of internal paths.

By default, the menu does not provide any styling. It can be rendered using HTML <ul> and <li> elements. It should be styled using CSS. The look and behaviour of menu items can be customized by just reimplementing the styling. For example, the WTabWidget is merely a specialized menu. By default the nav class from the Bootstrap theme is applied.

Top