Class MenuBar

java.lang.Object
All Implemented Interfaces:
HasAttachHandlers, HasCloseHandlers<PopupPanel>, HasHandlers, EventListener, HasAnimation, HasVisibility, IsWidget, PopupListener, EventListener

public class MenuBar extends Widget implements PopupListener, HasAnimation, HasCloseHandlers<PopupPanel>
A standard menu bar widget. A menu bar can contain any number of menu items, each of which can either fire a Scheduler.ScheduledCommand or open a cascaded menu bar.

CSS Style Rules

.gwt-MenuBar
the menu bar itself
.gwt-MenuBar-horizontal
dependent style applied to horizontal menu bars
.gwt-MenuBar-vertical
dependent style applied to vertical menu bars
.gwt-MenuBar .gwt-MenuItem
menu items
.gwt-MenuBar .gwt-MenuItem-selected
selected menu items
.gwt-MenuBar .gwt-MenuItemSeparator
section breaks between menu items
.gwt-MenuBar .gwt-MenuItemSeparator .menuSeparatorInner
inner component of section separators
.gwt-MenuBarPopup .menuPopupTopLeft
the top left cell
.gwt-MenuBarPopup .menuPopupTopLeftInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupTopCenter
the top center cell
.gwt-MenuBarPopup .menuPopupTopCenterInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupTopRight
the top right cell
.gwt-MenuBarPopup .menuPopupTopRightInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupMiddleLeft
the middle left cell
.gwt-MenuBarPopup .menuPopupMiddleLeftInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupMiddleCenter
the middle center cell
.gwt-MenuBarPopup .menuPopupMiddleCenterInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupMiddleRight
the middle right cell
.gwt-MenuBarPopup .menuPopupMiddleRightInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupBottomLeft
the bottom left cell
.gwt-MenuBarPopup .menuPopupBottomLeftInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupBottomCenter
the bottom center cell
.gwt-MenuBarPopup .menuPopupBottomCenterInner
the inner element of the cell
.gwt-MenuBarPopup .menuPopupBottomRight
the bottom right cell
.gwt-MenuBarPopup .menuPopupBottomRightInner
the inner element of the cell

Example

public class MenuBarExample implements EntryPoint {

  public void onModuleLoad() {
    // Make a command that we will execute from all leaves.
    Command cmd = new Command() {
      public void execute() {
        Window.alert("You selected a menu item!");
      }
    };

    // Make some sub-menus that we will cascade from the top menu.
    MenuBar fooMenu = new MenuBar(true);
    fooMenu.addItem("the", cmd);
    fooMenu.addItem("foo", cmd);
    fooMenu.addItem("menu", cmd);

    MenuBar barMenu = new MenuBar(true);
    barMenu.addItem("the", cmd);
    barMenu.addItem("bar", cmd);
    barMenu.addItem("menu", cmd);

    MenuBar bazMenu = new MenuBar(true);
    bazMenu.addItem("the", cmd);
    bazMenu.addItem("baz", cmd);
    bazMenu.addItem("menu", cmd);

    // Make a new menu bar, adding a few cascading menus to it.
    MenuBar menu = new MenuBar();
    menu.addItem("foo", fooMenu);
    menu.addItem("bar", barMenu);
    menu.addItem("baz", bazMenu);

    // Add it to the root panel.
    RootPanel.get().add(menu);
  }
}

Use in UiBinder Templates

MenuBar elements in UiBinder template files can have a vertical boolean attribute (which defaults to false), and may have only MenuItem elements as children. MenuItems may contain HTML and MenuBars.

For example:

 <g:MenuBar>
   <g:MenuItem>Higgledy
     <g:MenuBar vertical="true">
       <g:MenuItem>able</g:MenuItem>
       <g:MenuItem>baker</g:MenuItem>
       <g:MenuItem>charlie</g:MenuItem>
     </g:MenuBar>
   </g:MenuItem>
   <g:MenuItem>Piggledy
     <g:MenuBar vertical="true">
       <g:MenuItem>foo</g:MenuItem>
       <g:MenuItem>bar</g:MenuItem>
       <g:MenuItem>baz</g:MenuItem>
     </g:MenuBar>
   </g:MenuItem>
   <g:MenuItem><b>Pop!</b>
     <g:MenuBar vertical="true">
       <g:MenuItem>uno</g:MenuItem>
       <g:MenuItem>dos</g:MenuItem>
       <g:MenuItem>tres</g:MenuItem>
     </g:MenuBar>
   </g:MenuItem>
 </g:MenuBar>