java.awt

Class Menu

public class Menu extends MenuItem implements MenuContainer, Serializable

This class represents a pull down or tear off menu in Java's AWT.
Nested Class Summary
protected classMenu.AccessibleAWTMenu
Basic Accessibility class for Menu.
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
MenuItemadd(MenuItem item)
Adds the specified item to this menu.
voidadd(String label)
Add an item with the specified label to this menu.
voidaddNotify()
Creates the native peer for this object.
voidaddSeparator()
Adds a separator bar at the current menu location.
intcountItems()
Returns the number of items in this menu.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Menu.
MenuItemgetItem(int index)
Returns the item at the specified index.
intgetItemCount()
Returns the number of items in this menu.
voidinsert(MenuItem item, int index)
Inserts the specified menu item into this menu at the specified index.
voidinsert(String label, int index)
Inserts an item with the specified label into this menu at the specified index.
voidinsertSeparator(int index)
Inserts a separator bar at the specified index value.
booleanisTearOff()
Tests whether or not this menu is a tearoff.
StringparamString()
Returns a debugging string for this menu.
voidremove(int index)
Deletes the item at the specified index from this menu.
voidremove(MenuComponent item)
Removes the specifed item from the menu.
voidremoveAll()
Removes all the elements from this menu.
voidremoveNotify()
Destroys the native peer for this object.

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

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.

addNotify

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

addSeparator

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

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.

getAccessibleContext

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

Returns: the associated context

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.

getItemCount

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

Returns: The number of items in this menu.

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.

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.

isTearOff

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

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

paramString

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

Returns: A debugging string for this menu.

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.

Parameters: item The component to remove.

removeAll

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

removeNotify

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