public class MenuItem
extends BaseUIObject
MenuItem
is an entry in a Menu
. An ActionHandler
can be attached to a menu item which will be called when the item is
selected.Modifier and Type | Field and Description |
---|---|
static int |
MODIFIER_ALT
The Alt modifier
|
static int |
MODIFIER_CTRL
The Ctrl Modifier
|
static int |
MODIFIER_NONE
No modifier
|
static int |
MODIFIER_SHIFT
The Shift modifier.
|
Constructor and Description |
---|
MenuItem()
Creates a new separator.
|
MenuItem(java.lang.String name)
Creates a new menu item with the specified name.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getActionCommand()
Returns the menu item action command.
|
ActionHandler |
getActionHandler()
Returns the action handler associated with this item.
|
int |
getCommand()
Returns the menu item command.
|
Menu |
getMenu()
Returns the menu to which this item is attached.
|
java.lang.String |
getName()
Returns the menu item text.
|
char |
getShortcut()
Returns the shortcut key to activate the item.
|
int |
getShortcutModifier()
Returns the shortcut key modifier.
|
Menu |
getSubMenu()
Returns the sub menu attached to this menu item.
|
boolean |
hasSubMenu()
Returns whether this menu item has a submenu.
|
boolean |
isChecked()
Returns whether this menu item is checked.
|
boolean |
isEnabled()
Returns whether this menu item is enabled.
|
boolean |
isSeparator()
Returns whether this menu item is a separator.
|
void |
setActionCommand(java.lang.String actionCommand)
Sets the menu item action command.
|
ActionHandler |
setActionHandler(ActionHandler handler)
Associates an action handler to the item.
|
void |
setChecked(boolean checked)
Checks or unchecks a menu item.
|
void |
setEnabled(boolean enabled)
Enables or disables a menu item.
|
void |
setName(java.lang.String name)
Sets the menu item text.
|
void |
setShortcut(char key,
int modifier)
Sets the shortcut key to activate the item.
|
public static final int MODIFIER_NONE
public static final int MODIFIER_SHIFT
public static final int MODIFIER_ALT
public static final int MODIFIER_CTRL
public MenuItem(java.lang.String name)
name
- the name of the item as it appears in the menu.public MenuItem()
public boolean isEnabled()
true
if the item is enabled; false
otherwise.public void setEnabled(boolean enabled)
enabled
- true
if the item should be enabled; false
otherwise.public boolean isChecked()
true
if the item is checked; false
otherwise.public void setChecked(boolean checked)
checked
- true
if the item should be checked; false
otherwise.public boolean isSeparator()
true
if the menu item is a separator; false
otherwise.public java.lang.String getActionCommand()
public void setActionCommand(java.lang.String actionCommand)
actionCommand
- a string that may specify a command associated with the item.public int getCommand()
public java.lang.String getName()
public void setName(java.lang.String name)
name
- the menu item text.public boolean hasSubMenu()
true
if the menu item has a submenu; false
otherwise.public Menu getSubMenu()
null
if the item has no sub menu.public Menu getMenu()
null
if the item is not attached to any menu
yet.public char getShortcut()
public int getShortcutModifier()
public void setShortcut(char key, int modifier)
key
- shortcut key to activate the item. On Win32 platforms shortcuts are always uppercase keys.modifier
- a bit combination that indicates the modifier keys.public ActionHandler setActionHandler(ActionHandler handler)
class MyClass implements ActionHandler { ... MenuItem item = new MenuItem("MyItem"); item.setActionCommand("MyCommand"); item.setActionHandler(this); Application.getInstance().getMenuBar().getMenu(Application.MENU_MID_FILE_MENU).addMenuItem(item); public void handleAction (ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); String cmd = item.getActionCommand(); if (cmd.equals("MyCommand")) { JOptionPane.showMessageDialog(null, "Item " + item + " was clicked\n"); } } ... }
handler
- the action handler to associate to the item.public ActionHandler getActionHandler()
www.canto.com
Canto, the Canto logo, the Cumulus logo, and Cumulus are registered trademarks of Canto GmbH, registered in the U.S. and other countries.