Class Menu
- All Implemented Interfaces:
Adaptable
- 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: This class is not intended to be subclassed.
-
Constructor Summary
ConstructorDescriptionConstructs a new instance of this class given its parent, and sets the style for the instance so that the instance will be a popup menu on the given parent's shell.Menu
(Decorations parent, int style) Constructs a new instance of this class given its parent (which must be aDecorations
) and a style value describing its behavior and appearance.Constructs a new instance of this class given its parent (which must be aMenu
) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent.Constructs a new instance of this class given its parent (which must be aMenuItem
) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent menu. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHelpListener
(HelpListener listener) Adds the listener to the collection of listeners who will be notified when the help events are generated for the control, by sending it one of the messages defined in theHelpListener
interface.void
addMenuListener
(MenuListener 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 theMenuListener
interface.<T> T
getAdapter
(Class<T> adapter) Implementation of theAdaptable
interface.Returns the default menu item or null if none has been previously set.boolean
Returnstrue
if the receiver is enabled, andfalse
otherwise.getItem
(int index) Returns the item at the given, zero-relative index in the receiver.int
Returns the number of items contained in the receiver.MenuItem[]
getItems()
Returns a (possibly empty) array ofMenuItem
s which are the items in the receiver.int
Returns the orientation of the receiver, which will be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.Returns the receiver's parent, which must be aDecorations
.Returns the receiver's parent item, which must be aMenuItem
or null when the receiver is a root.Returns the receiver's parent item, which must be aMenu
or null when the receiver is a root.getShell()
Returns the receiver's shell.boolean
Returnstrue
if the receiver is visible, andfalse
otherwise.int
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.boolean
Returnstrue
if the receiver is enabled and all of the receiver's ancestors are enabled, andfalse
otherwise.boolean
Returnstrue
if the receiver is visible and all of the receiver's ancestors are visible andfalse
otherwise.void
removeHelpListener
(HelpListener listener) Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.void
removeMenuListener
(MenuListener listener) Removes the listener from the collection of listeners who will be notified when the menu events are generated for the control.void
setDefaultItem
(MenuItem item) Sets the default menu item to the argument or removes the default emphasis when the argument isnull
.void
setEnabled
(boolean enabled) Enables the receiver if the argument istrue
, and disables it otherwise.void
setLocation
(int x, int 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.void
setLocation
(Point 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.void
setOrientation
(int orientation) Sets the orientation of the receiver, which must be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.void
setVisible
(boolean visible) Marks the receiver as visible if the argument istrue
, and marks it invisible otherwise.Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
Constructor Details
-
Menu
Constructs a new instance of this class given its parent (which must be aMenu
) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent.- Parameters:
menu
- a menu which will be the parent of the new instance (cannot be null)- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
Menu
Constructs a new instance of this class given its parent (which must be aMenuItem
) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent menu.- Parameters:
parent
- a menu item which will be the parent of the new instance (cannot be null)- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
Menu
Constructs a new instance of this class given its parent, and sets the style for the instance so that the instance will be a popup menu on the given parent's shell.- Parameters:
parent
- a control which will be the parent of the new instance (cannot be null)- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
Menu
Constructs a new instance of this class given its parent (which must be aDecorations
) and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a decorations control which will be the parent of the new instance (cannot be null)style
- the style of menu to construct- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
-
Method Details
-
getParent
Returns the receiver's parent, which must be aDecorations
.- Returns:
- the receiver's parent
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getParentItem
Returns the receiver's parent item, which must be aMenuItem
or null when the receiver is a root.- Returns:
- the receiver's parent item
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getParentMenu
Returns the receiver's parent item, which must be aMenu
or null when the receiver is a root.- Returns:
- the receiver's parent item
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getAdapter
Description copied from class:Widget
Implementation of theAdaptable
interface.IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classWidget
- Parameters:
adapter
- the lookup class- Returns:
- an object that can be cast to the given class or
null
if there is no adapter associated with the given class.
-
setLocation
public void setLocation(int x, int 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.Note that this is different from most widgets where the location of the widget is relative to the parent.
Note that the platform window manager ultimately has control over the location of popup menus.
- Parameters:
x
- the new x coordinate for the receivery
- the new y coordinate for the receiver- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setLocation
Sets the location of the receiver, which must be a popup, to the point specified by the argument which is relative to the display.Note that this is different from most widgets where the location of the widget is relative to the parent.
Note that the platform window manager ultimately has control over the location of popup menus.
- Parameters:
location
- the new location for the receiver- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the point is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.0
-
getShell
Returns the receiver's shell. For all controls other than shells, this simply returns the control's nearest ancestor shell. Shells return themselves, even if they are children of other shells.- Returns:
- the receiver's shell
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setOrientation
public void setOrientation(int orientation) Sets the orientation of the receiver, which must be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.- Parameters:
orientation
- new orientation style- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.4
-
getOrientation
public int getOrientation()Returns the orientation of the receiver, which will be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.- Returns:
- the orientation style
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.4
-
setVisible
public void setVisible(boolean visible) Marks the receiver as visible if the argument istrue
, and marks it invisible otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
- Parameters:
visible
- the new visibility state- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getVisible
public boolean getVisible()Returnstrue
if the receiver is visible, andfalse
otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.
- Returns:
- the receiver's visibility state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
isVisible
public boolean isVisible()Returnstrue
if the receiver is visible and all of the receiver's ancestors are visible andfalse
otherwise.- Returns:
- the receiver's visibility state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Enables the receiver if the argument istrue
, and disables it otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Parameters:
enabled
- the new enabled state- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getEnabled
public boolean getEnabled()Returnstrue
if the receiver is enabled, andfalse
otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Returns:
- the receiver's enabled state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
isEnabled
public boolean isEnabled()Returnstrue
if the receiver is enabled and all of the receiver's ancestors are enabled, andfalse
otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Returns:
- the receiver's enabled state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getItemCount
public int getItemCount()Returns the number of items contained in the receiver.- Returns:
- the number of items
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getItems
Returns a (possibly empty) array ofMenuItem
s which are the items in the receiver.Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver.
- Returns:
- the items in the receiver
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getItem
Returns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.- Parameters:
index
- the index of the item to return- Returns:
- the item at the given index
- Throws:
IllegalArgumentException
-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
indexOf
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. If no item is found, returns -1.- Parameters:
menuItem
- the search item- Returns:
- the index of the item
- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the string is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setDefaultItem
Sets the default menu item to the argument or removes the default emphasis when the argument isnull
.- Parameters:
item
- the default menu item or null- Throws:
IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the menu item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.4
-
getDefaultItem
Returns the default menu item or null if none has been previously set.- Returns:
- the default menu item.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.4
-
-
addMenuListener
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 theMenuListener
interface.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
removeMenuListener
Removes the listener from the collection of listeners who will be notified when the menu events are generated for the control.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
addHelpListener
Adds the listener to the collection of listeners who will be notified when the help events are generated for the control, by sending it one of the messages defined in theHelpListener
interface.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
- See Also:
-
removeHelpListener
Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
- See Also: