java.awt
Class Menu

java.lang.Object
  extended by java.awt.MenuComponent
      extended by java.awt.MenuItem
          extended by java.awt.Menu
All Implemented Interfaces:
MenuContainer, Serializable, Accessible
Direct Known Subclasses:
PopupMenu

public class Menu
extends MenuItem
implements MenuContainer, Serializable

This class represents a pull down or tear off menu in Java's AWT.

See Also:
Serialized Form

Nested Class Summary
protected  class Menu.AccessibleAWTMenu
          Basic Accessibility class for Menu.
 
Nested classes/interfaces inherited from class java.awt.MenuItem
MenuItem.AccessibleAWTMenuItem
 
Nested classes/interfaces inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
Menu()
          Initializes a new instance of Menu with no label and that is not a tearoff;
Menu(String label)
          Initializes a new instance of Menu that is not a tearoff and that has the specified label.
Menu(String label, boolean isTearOff)
          Initializes a new instance of Menu with the specified label and tearoff status.
 
Method Summary
 MenuItem add(MenuItem item)
          Adds the specified item to this menu.
 void add(String label)
          Add an item with the specified label to this menu.
 void addNotify()
          Creates the native peer for this object.
 void addSeparator()
          Adds a separator bar at the current menu location.
 int countItems()
          Deprecated. As of JDK 1.1, replaced by getItemCount().
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this Menu.
 MenuItem getItem(int index)
          Returns the item at the specified index.
 int getItemCount()
          Returns the number of items in this menu.
 void insert(MenuItem item, int index)
          Inserts the specified menu item into this menu at the specified index.
 void insert(String label, int index)
          Inserts an item with the specified label into this menu at the specified index.
 void insertSeparator(int index)
          Inserts a separator bar at the specified index value.
 boolean isTearOff()
          Tests whether or not this menu is a tearoff.
 String paramString()
          Returns a debugging string for this menu.
 void remove(int index)
          Deletes the item at the specified index from this menu.
 void remove(MenuComponent item)
          Removes the specifed item from the menu.
 void removeAll()
          Removes all the elements from this menu.
 void removeNotify()
          Destroys the native peer for this object.
 
Methods inherited from class java.awt.MenuItem
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getListeners, getShortcut, isEnabled, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, postEvent, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

Menu

public Menu()
Initializes a new instance of Menu with no label and that is not a tearoff;

Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Menu

public Menu(String label)
Initializes a new instance of Menu that is not a tearoff and that has the specified label.

Parameters:
label - The menu label.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Menu

public Menu(String label,
            boolean isTearOff)
Initializes a new instance of Menu with the specified label and tearoff status.

Parameters:
label - The label for this menu
isTearOff - true if this menu is a tear off menu, false otherwise.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.
Method Detail

isTearOff

public boolean isTearOff()
Tests whether or not this menu is a tearoff.

Returns:
true if this menu is a tearoff, false otherwise.

getItemCount

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

Returns:
The number of items in this menu.

countItems

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

Returns the number of items in this menu.

Returns:
The number of items in this menu.

getItem

public MenuItem getItem(int index)
Returns the item at the specified index.

Parameters:
index - the item index.
Returns:
The item at the specified index.
Throws:
ArrayIndexOutOfBoundsException - If the index value is not valid.

add

public MenuItem add(MenuItem item)
Adds the specified item to this menu. If it was previously part of another menu, it is first removed from that menu.

Parameters:
item - The new item to add.
Returns:
The item that was added.

add

public void add(String label)
Add an item with the specified label to this menu.

Parameters:
label - The label of the menu item to add.

insert

public void insert(MenuItem item,
                   int index)
Inserts the specified menu item into this menu at the specified index. If the index is greater than or equal to the number of items already in the menu, the new item is added as the last item in the menu.

Parameters:
item - The menu item to add (null not permitted).
index - The index of the menu item (>= 0).
Throws:
IllegalArgumentException - if the index is less than zero.
NullPointerException - if item is null.

insert

public void insert(String label,
                   int index)
Inserts an item with the specified label into this menu at the specified index. If the index is greater than or equal to the number of items already in the menu, the new item is added as the last item in the menu.

Parameters:
label - The label of the item to add.
index - The index of the menu item (>= 0).
Throws:
IllegalArgumentException - If the index is less than zero.

addSeparator

public void addSeparator()
Adds a separator bar at the current menu location.


insertSeparator

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

Parameters:
index - The index at which to insert a separator bar.
Throws:
IllegalArgumentException - If the index is less than zero.
ArrayIndexOutOfBoundsException - If the index is otherwise invalid.

remove

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

Parameters:
index - The index of the item to remove.
Throws:
ArrayIndexOutOfBoundsException - If the index is otherwise invalid.

remove

public void remove(MenuComponent item)
Removes the specifed item from the menu. If the specified component does not exist, this method does nothing.

Specified by:
remove in interface MenuContainer
Parameters:
item - The component to remove.

removeAll

public void removeAll()
Removes all the elements from this menu.


addNotify

public void addNotify()
Creates the native peer for this object.

Overrides:
addNotify in class MenuItem

removeNotify

public void removeNotify()
Destroys the native peer for this object.

Overrides:
removeNotify in class MenuComponent

paramString

public String paramString()
Returns a debugging string for this menu.

Overrides:
paramString in class MenuItem
Returns:
A debugging string for this menu.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Menu. The context is created, if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class MenuItem
Returns:
the associated context