java.awt
Class Menu

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent 
      extended by java.awt.MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem 
          extended by java.awt.Menu
All Implemented Interfaces:
MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer , Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible
Direct Known Subclasses:
PopupMenu sample code for java.awt.PopupMenu definition code for java.awt.PopupMenu

public class Menu
extends MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem
implements MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer , Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible

A Menu object is a pull-down menu component that is deployed from a menu bar.

A menu can optionally be a tear-off menu. A tear-off menu can be opened and dragged away from its parent menu bar or menu. It remains on the screen after the mouse button has been released. The mechanism for tearing off a menu is platform dependent, since the look and feel of the tear-off menu is determined by its peer. On platforms that do not support tear-off menus, the tear-off property is ignored.

Each item in a menu must belong to the MenuItem class. It can be an instance of MenuItem, a submenu (an instance of Menu), or a check box (an instance of CheckboxMenuItem).

Since:
JDK1.0
See Also:
MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem , CheckboxMenuItem sample code for java.awt.CheckboxMenuItem definition code for java.awt.CheckboxMenuItem , Serialized Form

Nested Class Summary
protected  class Menu.AccessibleAWTMenu sample code for java.awt.Menu.AccessibleAWTMenu definition code for java.awt.Menu.AccessibleAWTMenu
          Inner class of Menu used to provide default support for accessibility.
 
Nested classes/interfaces inherited from class java.awt.MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem
MenuItem.AccessibleAWTMenuItem sample code for java.awt.MenuItem.AccessibleAWTMenuItem definition code for java.awt.MenuItem.AccessibleAWTMenuItem
 
Nested classes/interfaces inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent sample code for java.awt.MenuComponent.AccessibleAWTMenuComponent definition code for java.awt.MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
Menu sample code for java.awt.Menu.Menu() definition code for java.awt.Menu.Menu() ()
          Constructs a new menu with an empty label.
Menu sample code for java.awt.Menu.Menu(java.lang.String) definition code for java.awt.Menu.Menu(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  label)
          Constructs a new menu with the specified label.
Menu sample code for java.awt.Menu.Menu(java.lang.String, boolean) definition code for java.awt.Menu.Menu(java.lang.String, boolean) (String sample code for java.lang.String definition code for java.lang.String  label, boolean tearOff)
          Constructs a new menu with the specified label, indicating whether the menu can be torn off.
 
Method Summary
 MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem add sample code for java.awt.Menu.add(java.awt.MenuItem) definition code for java.awt.Menu.add(java.awt.MenuItem) (MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  mi)
          Adds the specified menu item to this menu.
 void add sample code for java.awt.Menu.add(java.lang.String) definition code for java.awt.Menu.add(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  label)
          Adds an item with the specified label to this menu.
 void addNotify sample code for java.awt.Menu.addNotify() definition code for java.awt.Menu.addNotify() ()
          Creates the menu's peer.
 void addSeparator sample code for java.awt.Menu.addSeparator() definition code for java.awt.Menu.addSeparator() ()
          Adds a separator line, or a hypen, to the menu at the current position.
 int countItems sample code for java.awt.Menu.countItems() definition code for java.awt.Menu.countItems() ()
          Deprecated. As of JDK version 1.1, replaced by getItemCount().
 AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.AccessibleContext getAccessibleContext sample code for java.awt.Menu.getAccessibleContext() definition code for java.awt.Menu.getAccessibleContext() ()
          Gets the AccessibleContext associated with this Menu.
 MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem getItem sample code for java.awt.Menu.getItem(int) definition code for java.awt.Menu.getItem(int) (int index)
          Gets the item located at the specified index of this menu.
 int getItemCount sample code for java.awt.Menu.getItemCount() definition code for java.awt.Menu.getItemCount() ()
          Get the number of items in this menu.
 void insert sample code for java.awt.Menu.insert(java.awt.MenuItem, int) definition code for java.awt.Menu.insert(java.awt.MenuItem, int) (MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  menuitem, int index)
          Inserts a menu item into this menu at the specified position.
 void insert sample code for java.awt.Menu.insert(java.lang.String, int) definition code for java.awt.Menu.insert(java.lang.String, int) (String sample code for java.lang.String definition code for java.lang.String  label, int index)
          Inserts a menu item with the specified label into this menu at the specified position.
 void insertSeparator sample code for java.awt.Menu.insertSeparator(int) definition code for java.awt.Menu.insertSeparator(int) (int index)
          Inserts a separator at the specified position.
 boolean isTearOff sample code for java.awt.Menu.isTearOff() definition code for java.awt.Menu.isTearOff() ()
          Indicates whether this menu is a tear-off menu.
 String sample code for java.lang.String definition code for java.lang.String paramString sample code for java.awt.Menu.paramString() definition code for java.awt.Menu.paramString() ()
          Returns a string representing the state of this Menu.
 void remove sample code for java.awt.Menu.remove(int) definition code for java.awt.Menu.remove(int) (int index)
          Removes the menu item at the specified index from this menu.
 void remove sample code for java.awt.Menu.remove(java.awt.MenuComponent) definition code for java.awt.Menu.remove(java.awt.MenuComponent) (MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent  item)
          Removes the specified menu item from this menu.
 void removeAll sample code for java.awt.Menu.removeAll() definition code for java.awt.Menu.removeAll() ()
          Removes all items from this menu.
 void removeNotify sample code for java.awt.Menu.removeNotify() definition code for java.awt.Menu.removeNotify() ()
          Removes the menu's peer.
 
Methods inherited from class java.awt.MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem
addActionListener sample code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) , deleteShortcut sample code for java.awt.MenuItem.deleteShortcut() definition code for java.awt.MenuItem.deleteShortcut() , disable sample code for java.awt.MenuItem.disable() definition code for java.awt.MenuItem.disable() , disableEvents sample code for java.awt.MenuItem.disableEvents(long) definition code for java.awt.MenuItem.disableEvents(long) , enable sample code for java.awt.MenuItem.enable() definition code for java.awt.MenuItem.enable() , enable sample code for java.awt.MenuItem.enable(boolean) definition code for java.awt.MenuItem.enable(boolean) , enableEvents sample code for java.awt.MenuItem.enableEvents(long) definition code for java.awt.MenuItem.enableEvents(long) , getActionCommand sample code for java.awt.MenuItem.getActionCommand() definition code for java.awt.MenuItem.getActionCommand() , getActionListeners sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners() , getLabel sample code for java.awt.MenuItem.getLabel() definition code for java.awt.MenuItem.getLabel() , getListeners sample code for java.awt.MenuItem.getListeners(java.lang.Class) definition code for java.awt.MenuItem.getListeners(java.lang.Class) , getShortcut sample code for java.awt.MenuItem.getShortcut() definition code for java.awt.MenuItem.getShortcut() , isEnabled sample code for java.awt.MenuItem.isEnabled() definition code for java.awt.MenuItem.isEnabled() , processActionEvent sample code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) definition code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) , processEvent sample code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) , removeActionListener sample code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) , setActionCommand sample code for java.awt.MenuItem.setActionCommand(java.lang.String) definition code for java.awt.MenuItem.setActionCommand(java.lang.String) , setEnabled sample code for java.awt.MenuItem.setEnabled(boolean) definition code for java.awt.MenuItem.setEnabled(boolean) , setLabel sample code for java.awt.MenuItem.setLabel(java.lang.String) definition code for java.awt.MenuItem.setLabel(java.lang.String) , setShortcut sample code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut)
 
Methods inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
dispatchEvent sample code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) , getFont sample code for java.awt.MenuComponent.getFont() definition code for java.awt.MenuComponent.getFont() , getName sample code for java.awt.MenuComponent.getName() definition code for java.awt.MenuComponent.getName() , getParent sample code for java.awt.MenuComponent.getParent() definition code for java.awt.MenuComponent.getParent() , getPeer sample code for java.awt.MenuComponent.getPeer() definition code for java.awt.MenuComponent.getPeer() , getTreeLock sample code for java.awt.MenuComponent.getTreeLock() definition code for java.awt.MenuComponent.getTreeLock() , postEvent sample code for java.awt.MenuComponent.postEvent(java.awt.Event) definition code for java.awt.MenuComponent.postEvent(java.awt.Event) , setFont sample code for java.awt.MenuComponent.setFont(java.awt.Font) definition code for java.awt.MenuComponent.setFont(java.awt.Font) , setName sample code for java.awt.MenuComponent.setName(java.lang.String) definition code for java.awt.MenuComponent.setName(java.lang.String) , toString sample code for java.awt.MenuComponent.toString() definition code for java.awt.MenuComponent.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 
Methods inherited from interface java.awt.MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer
getFont sample code for java.awt.MenuContainer.getFont() definition code for java.awt.MenuContainer.getFont() , postEvent sample code for java.awt.MenuContainer.postEvent(java.awt.Event) definition code for java.awt.MenuContainer.postEvent(java.awt.Event)
 

Constructor Detail

Menu sample code for java.awt.Menu() definition code for java.awt.Menu()

public Menu()
     throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Constructs a new menu with an empty label. This menu is not a tear-off menu.

Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.1
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()

Menu sample code for java.awt.Menu(java.lang.String) definition code for java.awt.Menu(java.lang.String)

public Menu(String sample code for java.lang.String definition code for java.lang.String  label)
     throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Constructs a new menu with the specified label. This menu is not a tear-off menu.

Parameters:
label - the menu's label in the menu bar, or in another menu of which this menu is a submenu.
Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()

Menu sample code for java.awt.Menu(java.lang.String, boolean) definition code for java.awt.Menu(java.lang.String, boolean)

public Menu(String sample code for java.lang.String definition code for java.lang.String  label,
            boolean tearOff)
     throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Constructs a new menu with the specified label, indicating whether the menu can be torn off.

Tear-off functionality may not be supported by all implementations of AWT. If a particular implementation doesn't support tear-off menus, this value is silently ignored.

Parameters:
label - the menu's label in the menu bar, or in another menu of which this menu is a submenu.
tearOff - if true, the menu is a tear-off menu.
Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.0.
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()
Method Detail

addNotify sample code for java.awt.Menu.addNotify() definition code for java.awt.Menu.addNotify()

public void addNotify()
Creates the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

Overrides:
addNotify sample code for java.awt.MenuItem.addNotify() definition code for java.awt.MenuItem.addNotify() in class MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem

removeNotify sample code for java.awt.Menu.removeNotify() definition code for java.awt.Menu.removeNotify()

public void removeNotify()
Removes the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

Overrides:
removeNotify sample code for java.awt.MenuComponent.removeNotify() definition code for java.awt.MenuComponent.removeNotify() in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent

isTearOff sample code for java.awt.Menu.isTearOff() definition code for java.awt.Menu.isTearOff()

public boolean isTearOff()
Indicates whether this menu is a tear-off menu.

Tear-off functionality may not be supported by all implementations of AWT. If a particular implementation doesn't support tear-off menus, this value is silently ignored.

Returns:
true if this is a tear-off menu; false otherwise.

getItemCount sample code for java.awt.Menu.getItemCount() definition code for java.awt.Menu.getItemCount()

public int getItemCount()
Get the number of items in this menu.

Returns:
the number of items in this menu.
Since:
JDK1.1

countItems sample code for java.awt.Menu.countItems() definition code for java.awt.Menu.countItems()

@Deprecated
public int countItems()
Deprecated. As of JDK version 1.1, replaced by getItemCount().


getItem sample code for java.awt.Menu.getItem(int) definition code for java.awt.Menu.getItem(int)

public MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  getItem(int index)
Gets the item located at the specified index of this menu.

Parameters:
index - the position of the item to be returned.
Returns:
the item located at the specified index.

add sample code for java.awt.Menu.add(java.awt.MenuItem) definition code for java.awt.Menu.add(java.awt.MenuItem)

public MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  add(MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  mi)
Adds the specified menu item to this menu. If the menu item has been part of another menu, removes it from that menu.

Parameters:
mi - the menu item to be added
Returns:
the menu item added
See Also:
insert(java.lang.String, int) sample code for java.awt.Menu.insert(java.lang.String, int) definition code for java.awt.Menu.insert(java.lang.String, int) , insert(java.awt.MenuItem, int) sample code for java.awt.Menu.insert(java.awt.MenuItem, int) definition code for java.awt.Menu.insert(java.awt.MenuItem, int)

add sample code for java.awt.Menu.add(java.lang.String) definition code for java.awt.Menu.add(java.lang.String)

public void add(String sample code for java.lang.String definition code for java.lang.String  label)
Adds an item with the specified label to this menu.

Parameters:
label - the text on the item
See Also:
insert(java.lang.String, int) sample code for java.awt.Menu.insert(java.lang.String, int) definition code for java.awt.Menu.insert(java.lang.String, int) , insert(java.awt.MenuItem, int) sample code for java.awt.Menu.insert(java.awt.MenuItem, int) definition code for java.awt.Menu.insert(java.awt.MenuItem, int)

insert sample code for java.awt.Menu.insert(java.awt.MenuItem, int) definition code for java.awt.Menu.insert(java.awt.MenuItem, int)

public void insert(MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  menuitem,
                   int index)
Inserts a menu item into this menu at the specified position.

Parameters:
menuitem - the menu item to be inserted.
index - the position at which the menu item should be inserted.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the value of index is less than zero
Since:
JDK1.1
See Also:
add(java.lang.String) sample code for java.awt.Menu.add(java.lang.String) definition code for java.awt.Menu.add(java.lang.String) , add(java.awt.MenuItem) sample code for java.awt.Menu.add(java.awt.MenuItem) definition code for java.awt.Menu.add(java.awt.MenuItem)

insert sample code for java.awt.Menu.insert(java.lang.String, int) definition code for java.awt.Menu.insert(java.lang.String, int)

public void insert(String sample code for java.lang.String definition code for java.lang.String  label,
                   int index)
Inserts a menu item with the specified label into this menu at the specified position. This is a convenience method for insert(menuItem, index).

Parameters:
label - the text on the item
index - the position at which the menu item should be inserted
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the value of index is less than zero
Since:
JDK1.1
See Also:
add(java.lang.String) sample code for java.awt.Menu.add(java.lang.String) definition code for java.awt.Menu.add(java.lang.String) , add(java.awt.MenuItem) sample code for java.awt.Menu.add(java.awt.MenuItem) definition code for java.awt.Menu.add(java.awt.MenuItem)

addSeparator sample code for java.awt.Menu.addSeparator() definition code for java.awt.Menu.addSeparator()

public void addSeparator()
Adds a separator line, or a hypen, to the menu at the current position.

See Also:
insertSeparator(int) sample code for java.awt.Menu.insertSeparator(int) definition code for java.awt.Menu.insertSeparator(int)

insertSeparator sample code for java.awt.Menu.insertSeparator(int) definition code for java.awt.Menu.insertSeparator(int)

public void insertSeparator(int index)
Inserts a separator at the specified position.

Parameters:
index - the position at which the menu separator should be inserted.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the value of index is less than 0.
Since:
JDK1.1
See Also:
addSeparator() sample code for java.awt.Menu.addSeparator() definition code for java.awt.Menu.addSeparator()

remove sample code for java.awt.Menu.remove(int) definition code for java.awt.Menu.remove(int)

public void remove(int index)
Removes the menu item at the specified index from this menu.

Parameters:
index - the position of the item to be removed.

remove sample code for java.awt.Menu.remove(java.awt.MenuComponent) definition code for java.awt.Menu.remove(java.awt.MenuComponent)

public void remove(MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent  item)
Removes the specified menu item from this menu.

Specified by:
remove sample code for java.awt.MenuContainer.remove(java.awt.MenuComponent) definition code for java.awt.MenuContainer.remove(java.awt.MenuComponent) in interface MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer
Parameters:
item - the item to be removed from the menu. If item is null or is not in this menu, this method does nothing.

removeAll sample code for java.awt.Menu.removeAll() definition code for java.awt.Menu.removeAll()

public void removeAll()
Removes all items from this menu.

Since:
JDK1.0.

paramString sample code for java.awt.Menu.paramString() definition code for java.awt.Menu.paramString()

public String sample code for java.lang.String definition code for java.lang.String  paramString()
Returns a string representing the state of this Menu. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString sample code for java.awt.MenuItem.paramString() definition code for java.awt.MenuItem.paramString() in class MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem
Returns:
the parameter string of this menu

getAccessibleContext sample code for java.awt.Menu.getAccessibleContext() definition code for java.awt.Menu.getAccessibleContext()

public AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.AccessibleContext  getAccessibleContext()
Gets the AccessibleContext associated with this Menu. For menus, the AccessibleContext takes the form of an AccessibleAWTMenu. A new AccessibleAWTMenu instance is created if necessary.

Specified by:
getAccessibleContext sample code for javax.accessibility.Accessible.getAccessibleContext() definition code for javax.accessibility.Accessible.getAccessibleContext() in interface Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible
Overrides:
getAccessibleContext sample code for java.awt.MenuItem.getAccessibleContext() definition code for java.awt.MenuItem.getAccessibleContext() in class MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem
Returns:
an AccessibleAWTMenu that serves as the AccessibleContext of this Menu