org.gnome.gtk

## Class Menu

- Object
- - org.freedesktop.bindings.Pointer
  - - org.freedesktop.bindings.Proxy
    - - org.gnome.glib.Object
      - - org.gnome.gtk.Widget
        - - org.gnome.gtk.Container
          - - org.gnome.gtk.MenuShell
            - - org.gnome.gtk.Menu

- Direct Known Subclasses:
    RecentChooserMenu

      public class Menu
      extends MenuShell

  A drop-down set of Widgets creating a menu. Menus consist of other `MenuItem`s. Menus are either placed inside a `MenuBar` or another MenuItem, thereby forming a sub-menu. An entire hierarchy of Menu structures can thus be created by appropriately placing Menus inside MenuBars or MenuItems.

  A "context menu" (a stand-alone menu which pops-up) can also be created; this is commonly used to create a context sensitive popup menu in response to a right-click (or left-click as the case may be); see the popup() method.

  For a broader explanation of the Menu API see `MenuShell`.

  GTK does have the ability to "tear" Menus off from the parent Container. After consistently poor results in usability testing, however, tear-off menus are now highly discouraged in the GNOME community. They are therefore not presented in the java-gnome bindings.

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

- - ### Nested Class Summary

    - ### 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.QueryTooltip, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Menu()` Construct a new Menu.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `popup()` Popup a context menu.
    `void` | `popup(int x, int y)` Having constructed a Menu to be used as the context menu, present it at the specified location.
    `void` | `popup(StatusIcon status)` A special case for popping up the context menu associated with a StatusIcon.
    `void` | `setAcceleratorGroup(AcceleratorGroup group)` This method must be called in order to have the key bindings in MenuItems work.

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

      `append, deactivate, insert, prepend`

    - ### 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, 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

    - #### Menu

          public Menu()

      Construct a new Menu.
      Since:
        4.0.3

  - ### Method Detail

    - #### popup

          public void popup()

      Popup a context menu. Use this when you create a Menu that will be used for the popup context menu in response to a right-click somewhere. The menu will appear where the mouse pointer is.

      Unlike normal Menus that are part of an application's MenuBar, context menus are not mapped automatically, so you need to have `showAll()` called on them once you're done building them to allocate their resources (otherwise you end up with a 1x1 pixel sized menu with nothing in it).

      Since:
        4.0.3

    - #### popup

          public void popup(int x,
                   int y)

      Having constructed a Menu to be used as the context menu, present it at the specified location. This is useful in conjunction with TextView's `getLocation()` if you wish to place the menu at the "cursor position" rather than where the mouse pointer is.
      Since:
        4.0.15

    - #### popup

          public void popup(StatusIcon status)

      A special case for popping up the context menu associated with a StatusIcon. Having constructed a Menu to be used as the context menu, you then call this from the `StatusIcon.PopupMenu` signal callback as follows:

           StatusIcon si;
           Menu context;
           ...

           si.connect(new StatusIcon.PopupMenu() {
               public void onPopupMenu(StatusIcon source, int button, int activateTime) {
                   context.popup(source);
               }
           });

      Don't forget to call `showAll()` on the Menu when you're done constructing it before trying to use it the first time.
      Since:
        4.0.3

    - #### setAcceleratorGroup

          public void setAcceleratorGroup(AcceleratorGroup group)

      This method must be called in order to have the key bindings in MenuItems work. It has to be the same AcceleratorGroup that was specified for the enclosing top level Window that this Menu will be a part of via Window's `addAcceleratorGroup()`.
      Since:
        4.0.16