Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client.ui
Class MenuBar

    java.lang.Object
      com.google.gwt.user.client.ui.UIObject
          com.google.gwt.user.client.ui.Widget
              com.google.gwt.user.client.ui.MenuBar

All Implemented Interfaces:
  EventListener, HasAnimation, PopupListener

    public class MenuBar

extends Widget
implements PopupListener, HasAnimation

A standard menu bar widget. A menu bar can contain any number of menu items, each of which can either fire a `Command` 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-MenuBar .menuPopupTopLeft { the top left cell }
- .gwt-MenuBar .menuPopupTopLeftInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupTopCenter { the top center cell }
- .gwt-MenuBar .menuPopupTopCenterInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupTopRight { the top right cell }
- .gwt-MenuBar .menuPopupTopRightInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupMiddleLeft { the middle left cell }
- .gwt-MenuBar .menuPopupMiddleLeftInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupMiddleCenter { the middle center cell }
- .gwt-MenuBar .menuPopupMiddleCenterInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupMiddleRight { the middle right cell }
- .gwt-MenuBar .menuPopupMiddleRightInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupBottomLeft { the bottom left cell }
- .gwt-MenuBar .menuPopupBottomLeftInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupBottomCenter { the bottom center cell }
- .gwt-MenuBar .menuPopupBottomCenterInner { the inner element of the cell }
- .gwt-MenuBar .menuPopupBottomRight { the bottom right cell }
- .gwt-MenuBar .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);
>       }
>     }

Nested Class Summary
`static interface` | `MenuBar.MenuBarImages` An `ImageBundle` that provides images for `MenuBar`.

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
`UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled`

Field Summary

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Constructor Summary
`MenuBar()` Creates an empty horizontal menu bar.
`MenuBar(boolean vertical)` Creates an empty menu bar.
`MenuBar(boolean vertical, MenuBar.MenuBarImages images)` Creates an empty menu bar that uses the specified image bundle for menu images.
`MenuBar(MenuBar.MenuBarImages images)` Creates an empty horizontal menu bar that uses the specified image bundle for menu images.

Method Summary
`MenuItem` | `addItem(MenuItem item)` Adds a menu item to the bar.
`MenuItem` | `addItem(java.lang.String text, boolean asHTML, Command cmd)` Adds a menu item to the bar, that will fire the given command when it is selected.
`MenuItem` | `addItem(java.lang.String text, boolean asHTML, MenuBar popup)` Adds a menu item to the bar, that will open the specified menu when it is selected.
`MenuItem` | `addItem(java.lang.String text, Command cmd)` Adds a menu item to the bar, that will fire the given command when it is selected.
`MenuItem` | `addItem(java.lang.String text, MenuBar popup)` Adds a menu item to the bar, that will open the specified menu when it is selected.
`MenuItemSeparator` | `addSeparator()` Adds a thin line to the `MenuBar` to separate sections of `MenuItem`s.
`MenuItemSeparator` | `addSeparator(MenuItemSeparator separator)` Adds a thin line to the `MenuBar` to separate sections of `MenuItem`s.
`void` | `clearItems()` Removes all menu items from this menu bar.
`boolean` | `getAutoOpen()` Gets whether this menu bar's child menus will open when the mouse is moved over it.
`protected java.util.List<MenuItem>` | `getItems()` Returns a list containing the `MenuItem` objects in the menu bar.
`protected MenuItem` | `getSelectedItem()` Returns the `MenuItem` that is currently selected (highlighted) by the user.
`boolean` | `isAnimationEnabled()`
`void` | `onBrowserEvent(Event event)` Fired whenever a browser event is received.
`protected void` | `onDetach()` This method is called when a widget is detached from the browser's document.
`protected void` | `onEnsureDebugId(java.lang.String baseID)` Affected Elements: -item# = the `MenuItem` at the specified index.
`void` | `onPopupClosed(PopupPanel sender, boolean autoClosed)` Fired when the popup is closed.
`void` | `removeItem(MenuItem item)` Removes the specified menu item from the bar.
`void` | `removeSeparator(MenuItemSeparator separator)` Removes the specified `MenuItemSeparator` from the bar.
`void` | `setAnimationEnabled(boolean enable)` Enable or disable animations.
`void` | `setAutoOpen(boolean autoOpen)` Sets whether this menu bar's child menus will open when the mouse is moved over it.

Methods inherited from class com.google.gwt.user.client.ui.Widget
`doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onLoad, onUnload, removeFromParent`

Methods inherited from class com.google.gwt.user.client.ui.UIObject
`addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### MenuBar

    public MenuBar()

  Creates an empty horizontal menu bar.

### MenuBar

    public MenuBar(boolean vertical)

  Creates an empty menu bar.

  Parameters:
    `vertical` - `true` to orient the menu bar vertically

### MenuBar

    public MenuBar(boolean vertical,
                   MenuBar.MenuBarImages images)

  Creates an empty menu bar that uses the specified image bundle for menu images.

  Parameters:
    `vertical` - `true` to orient the menu bar vertically
    `images` - a bundle that provides images for this menu

### MenuBar

    public MenuBar(MenuBar.MenuBarImages images)

  Creates an empty horizontal menu bar that uses the specified image bundle for menu images.

  Parameters:
    `images` - a bundle that provides images for this menu

Method Detail

### addItem

    public MenuItem addItem(MenuItem item)

  Adds a menu item to the bar.

  Parameters:
    `item` - the item to be added
  Returns:
    the `MenuItem` object

### addItem

    public MenuItem addItem(java.lang.String text,
                            boolean asHTML,
                            Command cmd)

  Adds a menu item to the bar, that will fire the given command when it is selected.

  Parameters:
    `text` - the item's text
    `asHTML` - `true` to treat the specified text as html
    `cmd` - the command to be fired
  Returns:
    the `MenuItem` object created

### addItem

    public MenuItem addItem(java.lang.String text,
                            boolean asHTML,
                            MenuBar popup)

  Adds a menu item to the bar, that will open the specified menu when it is selected.

  Parameters:
    `text` - the item's text
    `asHTML` - `true` to treat the specified text as html
    `popup` - the menu to be cascaded from it
  Returns:
    the `MenuItem` object created

### addItem

    public MenuItem addItem(java.lang.String text,
                            Command cmd)

  Adds a menu item to the bar, that will fire the given command when it is selected.

  Parameters:
    `text` - the item's text
    `cmd` - the command to be fired
  Returns:
    the `MenuItem` object created

### addItem

    public MenuItem addItem(java.lang.String text,
                            MenuBar popup)

  Adds a menu item to the bar, that will open the specified menu when it is selected.

  Parameters:
    `text` - the item's text
    `popup` - the menu to be cascaded from it
  Returns:
    the `MenuItem` object created

### addSeparator

    public MenuItemSeparator addSeparator()

  Adds a thin line to the `MenuBar` to separate sections of `MenuItem`s.

  Returns:
    the `MenuItemSeparator` object created

### addSeparator

    public MenuItemSeparator addSeparator(MenuItemSeparator separator)

  Adds a thin line to the `MenuBar` to separate sections of `MenuItem`s.

  Parameters:
    `separator` - the `MenuItemSeparator` to be added
  Returns:
    the `MenuItemSeparator` object

### clearItems

    public void clearItems()

  Removes all menu items from this menu bar.

### getAutoOpen

    public boolean getAutoOpen()

  Gets whether this menu bar's child menus will open when the mouse is moved over it.

  Returns:
    `true` if child menus will auto-open

### isAnimationEnabled

    public boolean isAnimationEnabled()

  Specified by:
    `isAnimationEnabled` in interface `HasAnimation`
  Returns:
    true if animations are enabled, false if not

### onBrowserEvent

    public void onBrowserEvent(Event event)

  Description copied from interface: `EventListener`
  Fired whenever a browser event is received.

  Specified by:
    `onBrowserEvent` in interface `EventListener`
  Overrides:
    `onBrowserEvent` in class `Widget`
  Parameters:
    `event` - the event received

### onPopupClosed

    public void onPopupClosed(PopupPanel sender,
                              boolean autoClosed)

  Description copied from interface: `PopupListener`
  Fired when the popup is closed.

  Specified by:
    `onPopupClosed` in interface `PopupListener`
  Parameters:
    `sender` - popup being closed.
    `autoClosed` - `true` if the popup was automatically closed; `false` if it was closed programmatically.

### removeItem

    public void removeItem(MenuItem item)

  Removes the specified menu item from the bar.

  Parameters:
    `item` - the item to be removed

### removeSeparator

    public void removeSeparator(MenuItemSeparator separator)

  Removes the specified `MenuItemSeparator` from the bar.

  Parameters:
    `separator` - the separator to be removed

### setAnimationEnabled

    public void setAnimationEnabled(boolean enable)

  Description copied from interface: `HasAnimation`
  Enable or disable animations.

  Specified by:
    `setAnimationEnabled` in interface `HasAnimation`
  Parameters:
    `enable` - true to enable, false to disable

### setAutoOpen

    public void setAutoOpen(boolean autoOpen)

  Sets whether this menu bar's child menus will open when the mouse is moved over it.

  Parameters:
    `autoOpen` - `true` to cause child menus to auto-open

### getItems

    protected java.util.List<MenuItem> getItems()

  Returns a list containing the `MenuItem` objects in the menu bar. If there are no items in the menu bar, then an empty `List` object will be returned.

  Returns:
    a list containing the `MenuItem` objects in the menu bar

### getSelectedItem

    protected MenuItem getSelectedItem()

  Returns the `MenuItem` that is currently selected (highlighted) by the user. If none of the items in the menu are currently selected, then `null` will be returned.

  Returns:
    the `MenuItem` that is currently selected, or `null` if no items are currently selected

### onDetach

    protected void onDetach()

  Description copied from class: `Widget`
  This method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the `Widget.onUnload()` method.

  Subclasses that override this method must call `super.onDetach()` to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects.

  Overrides:
    `onDetach` in class `Widget`

### onEnsureDebugId

    protected void onEnsureDebugId(java.lang.String baseID)

  Affected Elements:
  - -item# = the `MenuItem` at the specified index.

  Overrides:
    `onEnsureDebugId` in class `UIObject`
  Parameters:
    `baseID` - the base ID used by the main element
  See Also:
    `UIObject.onEnsureDebugId(String)`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD