org.gnome.gtk

## Class MenuItem

- Object
- - org.freedesktop.bindings.Pointer
  - - org.freedesktop.bindings.Proxy
    - - org.gnome.glib.Object
      - - org.gnome.gtk.Widget
        - - org.gnome.gtk.Container
          - - org.gnome.gtk.Bin
            - - org.gnome.gtk.MenuItem

- All Implemented Interfaces:
    Activatable
  Direct Known Subclasses:
    CheckMenuItem, ImageMenuItem, SeparatorMenuItem, TearoffMenuItem

      public class MenuItem
      extends Bin
      implements Activatable

  MenuItems are the basic elements that form a Menu. While MenuItems are Containers and are thus capable of containing other Widgets; in practise only the specialized MenuItem classes will work properly as they are what support highlighting, alignment, submenus, etc.

  MenuItems can be either left justified or right justified, but in general you should just leave this alone and it will do the right thing for your locale (left aligned for western languages, right aligned for right-to-left languages like Arabic).

  Right justification was initially designed to be used for "Help" Menus, but this is now considered a bad idea and is no longer used in GNOME.

  Since:
    4.0.3
  Author:
    Sebastian Mancke, Andrew Cowie, Srichand Pendyala, Vreixo Formoso

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `MenuItem.Activate` The handler interface for an activation.

    - ### Nested classes/interfaces inherited from class org.gnome.gtk.Widget

      `Widget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.Destroy, Widget.Draw, Widget.EnterNotifyEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MenuItem()` Construct a MenuItem
    `MenuItem(String mnemonicLabel)` Construct a MenuItem with a given text label.
    `MenuItem(String mnemonicLabel, MenuItem.Activate handler)` Construct a MenuItem with a given text label, and additionally connect a handler to its `MenuItem.Activate` signal.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `connect(MenuItem.Activate handler)` Connect an `MenuItem.Activate` handler to the widget.
    `Action` | `getRelatedAction()` Get the Action that is triggered when this Activatable is activated, if any.
    `Widget` | `getSubmenu()` Returns the submenu underneath this menu item, if any
    `void` | `setAccelerator(AcceleratorGroup group, Keyval keyval, ModifierType modifier)` Set a key binding for this MenuItem.
    `void` | `setRelatedAction(Action action)` Set the Action that is triggered when this Activatable is activated.
    `void` | `setSubmenu(Menu child)` Sets or replaces the MenuItem's submenu, or removes it if a `null` Menu is passed.

    - ### Methods inherited from class org.gnome.gtk.Bin

      `getChild`

    - ### Methods inherited from class org.gnome.gtk.Container

      `add, getChildren, remove, setBorderWidth`

    - ### Methods inherited from class org.gnome.gtk.Widget

      `activate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, destroy, getAllocatedHeight, getAllocatedWidth, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getPreferredHeightForWidthMinimum, getPreferredHeightForWidthNatural, getPreferredHeightMinimum, getPreferredHeightNatural, getPreferredWidthForHeightMinimum, getPreferredWidthForHeightNatural, getPreferredWidthMinimum, getPreferredWidthNatural, getRequestMode, getRequisition, getSensitive, getStyleContext, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, overrideBackground, overrideColor, overrideFont, queueDraw, queueDrawArea, realize, setAlignHorizontal, setAlignVertical, setCanDefault, setCanFocus, setEvents, setExpandHorizontal, setExpandVertical, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAll`

    - ### Methods inherited from class org.freedesktop.bindings.Pointer

      `toString`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MenuItem

          public MenuItem()

      Construct a MenuItem
      Since:
        4.0.3

    - #### MenuItem

          public MenuItem(String mnemonicLabel)

      Construct a MenuItem with a given text label. The label may contain underscores (the `_` character) which, if present, will indicate the mnemonic which will activate that MenuItem directly if that key is pressed (whilst the Menu is showing, obviously).
      Since:
        4.0.3

    - #### MenuItem

          public MenuItem(String mnemonicLabel,
                  MenuItem.Activate handler)

      Construct a MenuItem with a given text label, and additionally connect a handler to its `MenuItem.Activate` signal.

      This is equivalent to:

           item = new MenuItem("_My menu item");
           item.connect(handler);

      and affords you the convenience of being able to add a MenuItem fairly compactly:

           Menu editMenu;

           editMenu.append(new MenuItem("_Paste", new MenuItem.Activate() {
               public void onActivate(MenuItem source) {
                   ...
               }
           }));

      Since:
        4.0.4

  - ### Method Detail

    - #### connect

          public void connect(MenuItem.Activate handler)

      Connect an `MenuItem.Activate` handler to the widget.
      Since:
        4.0.3

    - #### getRelatedAction

          public Action getRelatedAction()

      Description copied from interface: `Activatable`
      Get the Action that is triggered when this Activatable is activated, if any.
      Specified by:
        `getRelatedAction` in interface `Activatable`

    - #### getSubmenu

          public Widget getSubmenu()

      Returns the submenu underneath this menu item, if any
      Returns:
        submenu for this menu item, or `null` if none.
      Since:
        4.0.3

    - #### setAccelerator

          public void setAccelerator(AcceleratorGroup group,
                            Keyval keyval,
                            ModifierType modifier)

      Set a key binding for this MenuItem.
      Since:
        4.0.16

    - #### setRelatedAction

          public void setRelatedAction(Action action)

      Description copied from interface: `Activatable`
      Set the Action that is triggered when this Activatable is activated.

      This replaced Action's connectProxy().

      Specified by:
        `setRelatedAction` in interface `Activatable`

    - #### setSubmenu

          public void setSubmenu(Menu child)

      Sets or replaces the MenuItem's submenu, or removes it if a `null` Menu is passed.
      Since:
        4.0.3