Top Description Inners Fields Constructors Methods
org.eclipse.swt.widgets

public Class Menu

extends Widget
Class Inheritance
Imports
java.util.*, org.eclipse.swt.*, org.eclipse.swt.events.*, org.eclipse.swt.graphics.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

Instances of this class are user interface objects that contain menu items.
Styles:
BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP
LEFT_TO_RIGHT, RIGHT_TO_LEFT
Events:
Help, Hide, Show

Note

Only one of BAR, DROP_DOWN and POP_UP may be specified. Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.

Important Note

This class is not intended to be subclassed.

See Also
Menu snippets, SWT Example: ControlExample, Sample code and further information

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv long
actionGroup

GTK4 only fields

pack-priv MenuItem
pack-priv boolean
pack-priv ImageList
pack-priv LinkedList<MenuItem>
pack-priv long
modelHandle

GTK4 only fields

pack-priv Decorations
pack-priv int
pack-priv LinkedList<Menu.Section>
pack-priv MenuItem
pack-priv long
shortcutController

GTK4 only fields

pack-priv int
x

pack-priv int
y

Inherited from org.eclipse.swt.widgets.Widget:
ACTIVATEACTIVATE_INVERSEAUTO_TEXT_DIRECTIONBACKGROUNDBACKSPACEBACKSPACE_INVERSEBUTTON_PRESS_EVENTBUTTON_PRESS_EVENT_INVERSEBUTTON_RELEASE_EVENTBUTTON_RELEASE_EVENT_INVERSECANVASCHANGE_VALUECHANGEDCHECK_SUBWINDOWCLICKEDCLOSE_REQUESTCOMMITCOMPUTE_SIZECONFIGURE_EVENTCOPY_CLIPBOARDCOPY_CLIPBOARD_INVERSECREATE_MENU_PROXYCUT_CLIPBOARDCUT_CLIPBOARD_INVERSEdataDAY_SELECTEDDAY_SELECTED_DOUBLE_CLICKDECELERATEDEFAULT_HEIGHTDEFAULT_WIDTHDELETE_EVENTDELETE_FROM_CURSORDELETE_FROM_CURSOR_INVERSEDELETE_RANGEDELETE_TEXTDIRECTION_CHANGEDDISABLEDdisplayDISPOSE_SENTDISPOSEDDPI_CHANGEDDRAG_DETECTDRAWENTERENTER_NOTIFY_EVENTEVENTEVENT_AFTEReventTableEXPAND_COLLAPSE_CURSOR_ROWEXPOSE_EVENTEXPOSE_EVENT_INVERSEFOCUSFOCUS_INFOCUS_IN_EVENTFOCUS_OUTFOCUS_OUT_EVENTFONTFOREGROUNDFOREIGN_HANDLEgdkSeatGrabPrepareFuncGESTURE_PRESSEDGESTURE_RELEASEDGRAB_FOCUShandleHANDLEHAS_AUTO_DIRECTIONHIDDENHIDEICON_RELEASEIM_UPDATEINPUTINSERT_TEXTIS_ACTIVEKEY_CHECK_SUBWINDOWKEY_GTK_CSSKEY_PRESS_EVENTKEY_PRESSEDKEY_RELEASE_EVENTKEY_RELEASEDKEYED_DATALAST_SIGNALLAYOUT_CHANGEDLAYOUT_CHILDLAYOUT_NEEDEDLEAVELEAVE_NOTIFY_EVENTMAPMAP_EVENTMENUMNEMONIC_ACTIVATEMONTH_CHANGEDMOTIONMOTION_INVERSEMOTION_NOTIFY_EVENTMOTION_NOTIFY_EVENT_INVERSEMOVE_CURSORMOVE_CURSOR_INVERSEMOVE_FOCUSMOVEDNOTIFY_DEFAULT_HEIGHTNOTIFY_DEFAULT_WIDTHNOTIFY_MAXIMIZEDNOTIFY_STATEOBSCUREDOUTPUTPARENT_BACKGROUNDPASTE_CLIPBOARDPASTE_CLIPBOARD_INVERSEPOPPED_UPPOPULATE_POPUPPOPUP_MENUPREEDIT_CHANGEDREALIZERELEASEDRESIZEDROW_ACTIVATEDROW_DELETEDROW_HAS_CHILD_TOGGLEDROW_INSERTEDSCROLLSCROLL_BEGINSCROLL_CHILDSCROLL_ENDSCROLL_EVENTSELECTSELECTION_DONESHOWSHOW_HELPSIZE_ALLOCATESIZE_ALLOCATE_GTK4SKIN_NEEDEDSTART_INTERACTIVE_SEARCHstateSTATUS_ICON_POPUP_MENUstyleSTYLE_UPDATEDSWITCH_PAGETEST_COLLAPSE_ROWTEST_EXPAND_ROWTEXT_BUFFER_INSERT_TEXTTHEME_BACKGROUNDTOGGLEDUNMAPUNMAP_EVENTUNREALIZEVALUE_CHANGEDWINDOW_STATE_EVENTZERO_HEIGHTZERO_WIDTH

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
pack-priv void
_setOrientation(int orientation)

pack-priv void
_setVisible(boolean visible)

pack-priv boolean

Returns:

true iff the location of menu is set and can be used successfully
ableToSetLocation
()

Bug 532074: setLocation method is limited on Wayland since Wayland has no global coordinates and we cannot use gdk_popup_at_rect if GdkWindow of getShell is not mapped.

pack-priv void
addAccelerators(long accelGroup)

public void
addHelpListener(HelpListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when help events are generated for the control, by sending it one of the messages defined in the HelpListener interface.

public void
addMenuListener(MenuListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when menus are hidden or shown, by sending it one of the messages defined in the MenuListener interface.

pack-priv void
adjustParentWindowWayland(long
a pointer to the GdkEvent
eventPtr
)

Lack of absolute coordinates make Wayland event windows inaccurate.

pack-priv static Control
checkNull(Control control)

pack-priv static Menu
pack-priv static MenuItem
pack-priv static int
checkStyle(int style)

pack-priv void
pack-priv void
pack-priv void
destroyWidget()

Overrides org.eclipse.swt.widgets.Widget.destroyWidget.

Overridden to fix memory leak on GTK3, see bug 573983
pack-priv void
fixMenus(Decorations newParent)

public MenuItem

Returns:

the default menu item.
getDefaultItem
()

Returns the default menu item or null if none has been previously set.

public boolean

Returns:

the receiver's enabled state
getEnabled
()

Returns true if the receiver is enabled, and false otherwise.

public MenuItem

Returns:

the item at the given index
getItem
(int
the index of the item to return
index
)

Returns the item at the given, zero-relative index in the receiver.

public int

Returns:

the number of items
getItemCount
()

Returns the number of items contained in the receiver.

public MenuItem[]

Returns:

the items in the receiver
getItems
()

Returns a (possibly empty) array of MenuItems which are the items in the receiver.

pack-priv String
public int

Returns:

the orientation style
getOrientation
()

Returns the orientation of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.

public Decorations

Returns:

the receiver's parent
getParent
()

Returns the receiver's parent, which must be a Decorations.

public MenuItem

Returns:

the receiver's parent item
getParentItem
()

Returns the receiver's parent item, which must be a MenuItem or null when the receiver is a root.

public Menu

Returns:

the receiver's parent item
getParentMenu
()

Returns the receiver's parent item, which must be a Menu or null when the receiver is a root.

public Shell

Returns:

the receiver's shell or null
getShell
()

Returns the receiver's shell.

public boolean

Returns:

the receiver's visibility state
getVisible
()

Returns true if the receiver is visible, and false otherwise.

pack-priv long
gtk3_show_help(long widget, long helpType)

Overrides org.eclipse.swt.widgets.Widget.gtk3_show_help.

pack-priv long
pack-priv long
gtk_menu_popped_up(long
the memory address of the menu which was popped up
widget
,
long
a pointer to the GdkRectangle containing the flipped location and size of the menu
flipped_rect
,
long
a pointer to the GdkRectangle containing the final (after all internal adjustments) location and size of the menu
final_rect
,
long
a boolean flag indicating whether the menu has been inverted along the X-axis
flipped_x
,
long
a boolean flag indicating whether the menu has been inverted along the Y-axis
flipped_y
)

Overrides org.eclipse.swt.widgets.Widget.gtk_menu_popped_up.

GTK3.22+ has API which allows clients of GTK to connect a menu to the "popped-up" signal.

pack-priv long
pack-priv void
public int

Returns:

the index of the item
indexOf
(MenuItem
the search item
item
)

Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item.

public boolean

Returns:

the receiver's enabled state
isEnabled
()

Returns true if the receiver is enabled and all of the receiver's ancestors are enabled, and false otherwise.

public boolean

Returns:

the receiver's visibility state
isVisible
()

Returns true if the receiver is visible and all of the receiver's ancestors are visible and false otherwise.

pack-priv void
pack-priv void
pack-priv void
pack-priv void
removeAccelerators(long accelGroup)

public void
removeHelpListener(HelpListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.

public void
removeMenuListener(MenuListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the menu events are generated for the control.

pack-priv void
pack-priv boolean
sendHelpEvent(long helpType)

public void
setDefaultItem(MenuItem
the default menu item or null
item
)

Sets the default menu item to the argument or removes the default emphasis when the argument is null.

public void
setEnabled(boolean
the new enabled state
enabled
)

Enables the receiver if the argument is true, and disables it otherwise.

public void
setLocation(int
the new x coordinate for the receiver
x
,
int
the new y coordinate for the receiver
y
)

Sets the location of the receiver, which must be a popup, to the point specified by the arguments which are relative to the display.

public void
setLocation(Point
the new location for the receiver
location
)

Sets the location of the receiver, which must be a popup, to the point specified by the argument which is relative to the display.

pack-priv void
setLocationInPixels(int x, int y)

pack-priv void
public void
setOrientation(int
new orientation style
orientation
)

Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.

pack-priv void
public void
setVisible(boolean
the new visibility state
visible
)

Marks the receiver as visible if the argument is true, and marks it invisible otherwise.

pack-priv void
verifyMenuPosition(int
the current number of items in the menu, just before it's about to be shown/popped-up
itemCount
)

Feature in GTK3 on X11: context menus in SWT are populated dynamically, sometimes asynchronously outside of SWT (i.e. in Platform UI).

Inherited from org.eclipse.swt.widgets.Widget:
_addListeneraddDisposeListeneraddListenercellDataProccheckBitscheckOpencheckOrientationcheckParentcheckSubclasscheckWidgetconvertPangoFontDescriptionToCsscssHandlederegisterdisposedpiChangedenterMotionProcerrorfilterProcfiltersfixMnemonicfixMnemonicfixMnemonicfocusProcfontHeightgdk_event_freegdk_event_get_stategdk_event_get_surface_or_windowgdk_pointer_grabgdk_pointer_ungrabgdk_surface_get_sizegdk_window_get_sizeGdkSeatGrabPrepareFuncgesturePressReleaseProcgetDatagetDatagetDisplaygetListenersgetNamegetStylegtk4_drawgtk4_enter_eventgtk4_focus_enter_eventgtk4_focus_leave_eventgtk4_focus_window_eventgtk4_key_press_eventgtk4_key_release_eventgtk4_leave_eventgtk4_motion_eventgtk4_scroll_eventgtk_activategtk_adjustment_getgtk_box_newgtk_box_pack_endgtk_box_set_child_packinggtk_button_press_eventgtk_button_release_eventgtk_cell_renderer_get_preferred_sizegtk_change_valuegtk_changedgtk_clickedgtk_close_requestgtk_commitgtk_configure_eventgtk_container_get_border_width_or_margingtk_container_set_border_widthgtk_create_menu_proxygtk_day_selectedgtk_day_selected_double_clickgtk_delete_eventgtk_delete_rangegtk_delete_textgtk_drawgtk_enter_notify_eventgtk_event_aftergtk_expand_collapse_cursor_rowgtk_focusgtk_focus_in_eventgtk_focus_out_eventgtk_gesture_press_eventgtk_gesture_release_eventgtk_grab_focusgtk_icon_releasegtk_inputgtk_insert_textgtk_key_press_eventgtk_key_release_eventgtk_leave_notify_eventgtk_mapgtk_map_eventgtk_mnemonic_activategtk_month_changedgtk_motion_notify_eventgtk_move_focusgtk_outputgtk_populate_popupgtk_popup_menugtk_preedit_changedgtk_realizegtk_row_activatedgtk_row_has_child_toggledgtk_scroll_childgtk_scroll_eventgtk_selectgtk_selection_donegtk_size_allocategtk_start_interactive_searchgtk_status_icon_popup_menugtk_style_updatedgtk_switch_pagegtk_test_collapse_rowgtk_test_expand_rowgtk_text_buffer_insert_textgtk_timergtk_toggledgtk_tree_view_column_cell_get_positiongtk_unmapgtk_unmap_eventgtk_unrealizegtk_value_changedgtk_widget_get_preferred_sizegtk_widget_get_surfacegtk_widget_get_windowgtk_widget_size_allocategtk_window_state_eventhookshoverProcisActiveisAutoDirectionisDisposedisListeningisValidSubclassisValidThreadkeyPressReleaseProcleaveProcmnemonicHitmnemonicMatchnotifyCreationTrackernotifyDisposalTrackernotifyListenersnotifyProcnotifyStatepaintSurfacepaintWindowpostEventpostEventregisterreleasereleaseHandleremoveDisposeListenerremoveListenerremoveListenerrendererGetPreferredWidthProcrendererRenderProcrendererSnapshotProcreskinreskinWidgetscrollProcsendEventsendEventsendEventsendEventsendIMKeyEventsendKeyEventsendSelectionEventsendSelectionEventsetButtonStatesetDatasetDatasetFontDescriptionsetInputStatesetKeyStatesetLocationStatesetTabGroupFocussetTabItemFocussetToolTipTextshellMapProcsizeAllocateProcsizeRequestProcsnapshotToDrawtimerProctopHandletoStringtranslateTraversalwindowActiveProcwindowProcwindowProcwindowProcwindowProcwindowProc