java.lang.Object
java.awt.MenuComponent
java.awt.MenuItem
java.awt.Menu
protected class
Menu.AccessibleAWTMenu
Menu()
Menu
with no label and that
is not a tearoff;
void
addNotify()
void
addSeparator()
int
countItems()
AccessibleContext
getAccessibleContext()
Menu
.
int
getItemCount()
void
void
void
insertSeparator(int index)
boolean
isTearOff()
String
paramString()
void
remove(int index)
void
remove(MenuComponent item)
void
removeAll()
void
removeNotify()
addActionListener
, addNotify
, deleteShortcut
, disable
, disableEvents
, enable
, enable
, enableEvents
, extends EventListener> T[] getListeners
, getAccessibleContext
, getActionCommand
, getActionListeners
, getLabel
, getShortcut
, isEnabled
, paramString
, processActionEvent
, processEvent
, removeActionListener
, setActionCommand
, setEnabled
, setLabel
, setShortcut
public Menu()
Initializes a new instance ofMenu
with no label and that is not a tearoff;
- Throws:
HeadlessException
- If GraphicsEnvironment.isHeadless() is true.
public Menu(String label)
Initializes a new instance ofMenu
that is not a tearoff and that has the specified label.
- Parameters:
label
- The menu label.
- Throws:
HeadlessException
- If GraphicsEnvironment.isHeadless() is true.
public Menu(String label, boolean isTearOff)
Initializes a new instance ofMenu
with the specified label and tearoff status.
- Parameters:
label
- The label for this menuisTearOff
-true
if this menu is a tear off menu,false
otherwise.
- Throws:
HeadlessException
- If GraphicsEnvironment.isHeadless() is true.
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.
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.
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.
public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with thisMenu
. The context is created, if necessary.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface MenuItem
- Returns:
- the associated context
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.
public int getItemCount()
Returns the number of items in this menu.
- Returns:
- The number of items in this menu.
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
- ifitem
isnull
.
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.
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.
public boolean isTearOff()
Tests whether or not this menu is a tearoff.
- Returns:
true
if this menu is a tearoff,false
otherwise.
public String paramString()
Returns a debugging string for this menu.
- Overrides:
- paramString in interface MenuItem
- Returns:
- A debugging string for this menu.
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.
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.
public void removeNotify()
Destroys the native peer for this object.
- Overrides:
- removeNotify in interface MenuComponent