GWT 2.7.0

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

    java.lang.Object
      com.google.gwt.user.client.ui.UIObject
          com.google.gwt.user.client.ui.MenuItem

All Implemented Interfaces:
  HasSafeHtml, HasEnabled, HasHTML, HasText, HasVisibility

    public class MenuItem

extends UIObject
implements HasHTML, HasEnabled, HasSafeHtml

An entry in a `MenuBar`. Menu items can either fire a `Scheduler.ScheduledCommand` when they are clicked, or open a cascading sub-menu. Each menu item is assigned a unique DOM id in order to support ARIA. See `Accessibility` for more information.

Nested Class Summary

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, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR`

Constructor Summary
`MenuItem(SafeHtml html)` Constructs a new menu item that fires a command when it is selected.
`MenuItem(SafeHtml html, MenuBar subMenu)` Constructs a new menu item that cascades to a sub-menu when it is selected.
`MenuItem(SafeHtml html, Scheduler.ScheduledCommand cmd)` Constructs a new menu item that fires a command when it is selected.
`MenuItem(java.lang.String text, boolean asHTML)`
`MenuItem(java.lang.String text, boolean asHTML, MenuBar subMenu)` Constructs a new menu item that cascades to a sub-menu when it is selected.
`MenuItem(java.lang.String text, boolean asHTML, Scheduler.ScheduledCommand cmd)` Constructs a new menu item that fires a command when it is selected.
`MenuItem(java.lang.String text, MenuBar subMenu)` Constructs a new menu item that cascades to a sub-menu when it is selected.
`MenuItem(java.lang.String text, Scheduler.ScheduledCommand cmd)` Constructs a new menu item that fires a command when it is selected.

Method Summary
`Command` | `getCommand()` Deprecated. use `getScheduledCommand()` instead
`java.lang.String` | `getHTML()` Gets this object's contents as HTML.
`MenuBar` | `getParentMenu()` Gets the menu that contains this item.
`Scheduler.ScheduledCommand` | `getScheduledCommand()` Gets the scheduled command associated with this item.
`MenuBar` | `getSubMenu()` Gets the sub-menu associated with this item.
`java.lang.String` | `getText()` Gets this object's text.
`boolean` | `isEnabled()` Returns true if the widget is enabled, false if not.
`protected void` | `onEnsureDebugId(java.lang.String baseID)` Also sets the Debug IDs of MenuItems in the submenu of this `MenuItem` if a submenu exists.
`void` | `setCommand(Command cmd)` Deprecated. use `#setScheduledCommand(ScheduledCommand)` instead
`void` | `setEnabled(boolean enabled)` Sets whether this widget is enabled.
`void` | `setHTML(SafeHtml html)` Sets this object's contents via known-safe HTML.
`void` | `setHTML(java.lang.String html)` Sets this object's contents via HTML.
`(package private) void` | `setParentMenu(MenuBar parentMenu)`
`void` | `setScheduledCommand(Scheduler.ScheduledCommand cmd)` Sets the scheduled command associated with this item.
`protected void` | `setSelectionStyle(boolean selected)`
`void` | `setSubMenu(MenuBar subMenu)` Sets the sub-menu associated with this item.
`void` | `setText(java.lang.String text)` Sets this object's text.

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, replaceElement, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, sinkEvents, toString, unsinkEvents`

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

Constructor Detail

### MenuItem

    public MenuItem(SafeHtml html)

  Constructs a new menu item that fires a command when it is selected.

  Parameters:
    `html` - the item's html text

### MenuItem

    public MenuItem(SafeHtml html,
                    Scheduler.ScheduledCommand cmd)

  Constructs a new menu item that fires a command when it is selected.

  Parameters:
    `html` - the item's text
    `cmd` - the command to be fired when it is selected

### MenuItem

    public MenuItem(SafeHtml html,
                    MenuBar subMenu)

  Constructs a new menu item that cascades to a sub-menu when it is selected.

  Parameters:
    `html` - the item's text
    `subMenu` - the sub-menu to be displayed when it is selected

### MenuItem

    public MenuItem(java.lang.String text,
                    boolean asHTML,
                    Scheduler.ScheduledCommand cmd)

  Constructs a new menu item that fires a 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 when it is selected

### MenuItem

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

  Constructs a new menu item that cascades to a sub-menu when it is selected.

  Parameters:
    `text` - the item's text
    `asHTML` - `true` to treat the specified text as html
    `subMenu` - the sub-menu to be displayed when it is selected

### MenuItem

    public MenuItem(java.lang.String text,
                    Scheduler.ScheduledCommand cmd)

  Constructs a new menu item that fires a command when it is selected.

  Parameters:
    `text` - the item's text
    `cmd` - the command to be fired when it is selected

### MenuItem

    public MenuItem(java.lang.String text,
                    MenuBar subMenu)

  Constructs a new menu item that cascades to a sub-menu when it is selected.

  Parameters:
    `text` - the item's text
    `subMenu` - the sub-menu to be displayed when it is selected

### MenuItem

    MenuItem(java.lang.String text,
             boolean asHTML)

Method Detail

### getCommand

    @Deprecated
    public Command getCommand()

  Deprecated. use `getScheduledCommand()` instead

  Gets the command associated with this item. If a scheduled command is associated with this item a command that can be used to execute the scheduled command will be returned.

  Returns:
    the command

### getHTML

    public java.lang.String getHTML()

  Description copied from interface: `HasHTML`
  Gets this object's contents as HTML.

  Specified by:
    `getHTML` in interface `HasHTML`
  Returns:
    the object's HTML

### getParentMenu

    public MenuBar getParentMenu()

  Gets the menu that contains this item.

  Returns:
    the parent menu, or `null` if none exists.

### getScheduledCommand

    public Scheduler.ScheduledCommand getScheduledCommand()

  Gets the scheduled command associated with this item.

  Returns:
    this item's scheduled command, or `null` if none exists

### getSubMenu

    public MenuBar getSubMenu()

  Gets the sub-menu associated with this item.

  Returns:
    this item's sub-menu, or `null` if none exists

### getText

    public java.lang.String getText()

  Description copied from interface: `HasText`
  Gets this object's text.

  Specified by:
    `getText` in interface `HasText`
  Returns:
    the object's text

### isEnabled

    public boolean isEnabled()

  Description copied from interface: `HasEnabled`
  Returns true if the widget is enabled, false if not.

  Specified by:
    `isEnabled` in interface `HasEnabled`

### setCommand

    @Deprecated
    public void setCommand(Command cmd)

  Deprecated. use `#setScheduledCommand(ScheduledCommand)` instead

  Sets the command associated with this item.

  Parameters:
    `cmd` - the command to be associated with this item

### setEnabled

    public void setEnabled(boolean enabled)

  Description copied from interface: `HasEnabled`
  Sets whether this widget is enabled.

  Specified by:
    `setEnabled` in interface `HasEnabled`
  Parameters:
    `enabled` - `true` to enable the widget, `false` to disable it

### setHTML

    public void setHTML(SafeHtml html)

  Description copied from interface: `HasSafeHtml`
  Sets this object's contents via known-safe HTML.

  The object will behave exactly the same as when a widget's `HasHTML.setHTML(String)` method is invoked; however the `SafeHtml` passed to this method observes the contract that it can be used in an HTML context without causing unsafe script execution. Thus, unlike `HasHTML.setHTML(String)`, using this method cannot result in Cross-Site Scripting security vulnerabilities.

  Specified by:
    `setHTML` in interface `HasSafeHtml`
  Parameters:
    `html` - the object's new HTML, represented as a `SafeHtml` object

### setHTML

    public void setHTML(java.lang.String html)

  Description copied from interface: `HasHTML`
  Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using `HasText.setText(String)` whenever possible.

  Specified by:
    `setHTML` in interface `HasHTML`
  Parameters:
    `html` - the object's new HTML

### setScheduledCommand

    public void setScheduledCommand(Scheduler.ScheduledCommand cmd)

  Sets the scheduled command associated with this item.

  Parameters:
    `cmd` - the scheduled command to be associated with this item

### setSubMenu

    public void setSubMenu(MenuBar subMenu)

  Sets the sub-menu associated with this item.

  Parameters:
    `subMenu` - this item's new sub-menu

### setText

    public void setText(java.lang.String text)

  Description copied from interface: `HasText`
  Sets this object's text.

  Specified by:
    `setText` in interface `HasText`
  Parameters:
    `text` - the object's new text

### onEnsureDebugId

    protected void onEnsureDebugId(java.lang.String baseID)

  Also sets the Debug IDs of MenuItems in the submenu of this `MenuItem` if a submenu exists.

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

### setSelectionStyle

    protected void setSelectionStyle(boolean selected)

### setParentMenu

    void setParentMenu(MenuBar parentMenu)

GWT 2.7.0