org.eclipse.swt.widgets
Class MenuItem

java.lang.Object
  |
  +--org.eclipse.swt.widgets.Widget
        |
        +--org.eclipse.swt.widgets.Item
              |
              +--org.eclipse.swt.widgets.MenuItem
All Implemented Interfaces:
Drawable, Runnable

public class MenuItem
extends Item

Instances of this class represent a selectable user interface object that issues notification when pressed and released.

Styles:
CHECK, CASCADE, PUSH, RADIO, SEPARATOR
Events:
Arm, Help, Selection

Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified.

IMPORTANT: This class is not intended to be subclassed.


Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Widget
h, INCMD_DISPOSE, INCMD_EXTKEY, INCMD_KEY, INCMD_LDOWN, INCMD_LUP, INCMD_MENU, INCMD_POS, UPDATEITEM_ENABLED, UPDATEITEM_NAME, w, x, y
 
Constructor Summary
MenuItem(Menu parent, int style)
          Constructs a new instance of this class given its parent (which must be a Menu) and a style value describing its behavior and appearance.
 
Method Summary
 void setAccelerator(int accelerator)
          Sets the widget accelerator.
 void setEnabled(boolean state)
          Enables or disables a MenuItem.
 void setText(String string)
          Sets the text of the MenuItem.
 
Methods inherited from class org.eclipse.swt.widgets.Item
getImage, getText, setImage
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addListener, computeSize, dispose, focusState, getBorderWidth, getDisplayArea, getSelection, getStyle, isDisposed, removeListener, setBounds, setCursor, stop
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, toString
 
Methods inherited from interface java.lang.Runnable
run
 
Methods inherited from interface org.eclipse.swt.graphics.Drawable
drawLine, drawRect, drawText, setColor
 

Constructor Detail

MenuItem

public MenuItem(Menu parent,
                int style)
Constructs a new instance of this class given its parent (which must be a Menu) and a style value describing its behavior and appearance. The item is added to the end of the items maintained by its parent.

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 the int "|" operator) two or more of those SWT 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 menu control which will be the parent of the new instance (cannot be null)
style - the style of control to construct
Throws:
IllegalArgumentException -
SWTException -
See Also:
SWT.CHECK, SWT.CASCADE, SWT.PUSH, SWT.RADIO, SWT.SEPARATOR, Widget#checkSubclass, Widget.getStyle()
Method Detail

setAccelerator

public void setAccelerator(int accelerator)
Sets the widget accelerator. An accelerator is the bit-wise OR of zero or more modifier masks and a key. Examples: SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2. SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2.

Parameters:
accelerator - an integer that is the bit-wise OR of masks and a key
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

setEnabled

public void setEnabled(boolean state)
Enables or disables a MenuItem. Per default, a MenuItem is enabled upon creation.

Parameters:
state - true or false

setText

public void setText(String string)
Sets the text of the MenuItem. The string may include a mnemonic character and accelerator text.

Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, a selection event occurs. On most platforms, the mnemonic appears underlined but may be emphasised in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single &' to be displayed.

Accelerator text is indicated by the '\t' character. On platforms that support accelerator text, the text that follows the '\t' character is displayed to the user, typically indicating the key stroke that will cause the item to become selected. On most platforms, the accelerator text appears right aligned in the menu. Setting the accelerator text does not install the accelerator key sequence. The accelerator key sequence is installed using #setAccelerator.

Overrides:
setText in class Item
Parameters:
string - the new text
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the text 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:
setAccelerator(int)