java.awt
public class Menu extends MenuItem implements MenuContainer, Serializable
Modifier and Type | Class and Description |
---|---|
protected class |
Menu.AccessibleAWTMenu
Basic Accessibility class for Menu.
|
MenuItem.AccessibleAWTMenuItem
MenuComponent.AccessibleAWTMenuComponent
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
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.
|
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getListeners, getShortcut, isEnabled, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, postEvent, setFont, setName, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getFont, postEvent
public Menu()
Menu
with no label and that
is not a tearoff;HeadlessException
- If GraphicsEnvironment.isHeadless() is true.public Menu(String label)
Menu
that is not a tearoff and
that has the specified label.label
- The menu label.HeadlessException
- If GraphicsEnvironment.isHeadless() is true.public Menu(String label, boolean isTearOff)
Menu
with the specified
label and tearoff status.label
- The label for this menuisTearOff
- true
if this menu is a tear off menu,
false
otherwise.HeadlessException
- If GraphicsEnvironment.isHeadless() is true.public boolean isTearOff()
true
if this menu is a tearoff, false
otherwise.public int getItemCount()
public int countItems()
public MenuItem getItem(int index)
index
- the item index.ArrayIndexOutOfBoundsException
- If the index value is not valid.public MenuItem add(MenuItem item)
item
- The new item to add.public void add(String label)
label
- The label of the menu item to add.public void insert(MenuItem item, int index)
item
- The menu item to add (null
not permitted).index
- The index of the menu item (>= 0).IllegalArgumentException
- if the index is less than zero.NullPointerException
- if item
is null
.public void insert(String label, int index)
label
- The label of the item to add.index
- The index of the menu item (>= 0).IllegalArgumentException
- If the index is less than zero.public void addSeparator()
public void insertSeparator(int index)
index
- The index at which to insert a separator bar.IllegalArgumentException
- If the index is less than zero.ArrayIndexOutOfBoundsException
- If the index is otherwise invalid.public void remove(int index)
index
- The index of the item to remove.ArrayIndexOutOfBoundsException
- If the index is otherwise invalid.public void remove(MenuComponent item)
remove
in interface MenuContainer
item
- The component to remove.public void removeAll()
public void addNotify()
public void removeNotify()
removeNotify
in class MenuComponent
public String paramString()
paramString
in class MenuItem
public AccessibleContext getAccessibleContext()
Menu
.
The context is created, if necessary.getAccessibleContext
in interface Accessible
getAccessibleContext
in class MenuItem