APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public Class Menu

extends MenuItem
implements MenuContainer, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, java.awt.MenuContainer
Known Direct Subclasses
java.awt.PopupMenu
Imports
java.awt.event.KeyEvent, java.awt.peer.MenuPeer, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, java.util.ArrayList, .Enumeration, .EventListener, .Vector, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, sun.awt.AWTAccessor

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).

Author
Sami Shaio
Since
1.0
See Also
java.awt.MenuItem, java.awt.CheckboxMenuItem

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
Menu.AccessibleAWTMenu

Inner class of Menu used to provide default support for accessibility.

Field Summary

Modifier and TypeField and Description
private static final String
pack-priv volatile boolean
isHelpMenu

This field will be set to true if the Menu in question is actually a help menu.

private final Vector<MenuItem>
items

A vector of the items that will be part of the Menu.

private static int
private static final long
serialVersionUID

Hides java.awt.MenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
private final boolean
tearOff

This field indicates whether the menu has the tear of property or not.

Inherited from java.awt.MenuItem:
eventMasklabel

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
public MenuItem

Returns:

the menu item added
add
(MenuItem
the menu item to be added
mi
)

Adds the specified menu item to this menu.

public void
add(String
the text on the item
label
)

Adds an item with the specified label to this menu.

public void
addNotify()

Overrides java.awt.MenuItem.addNotify.

Creates the menu's peer.

public void
addSeparator()

Adds a separator line, or a hyphen, to the menu at the current position.

pack-priv String
constructComponentName()

Overrides java.awt.MenuItem.constructComponentName.

Construct a name for this MenuComponent.

public int

Returns:

the number of items in this menu
countItems
()
Deprecated As of JDK version 1.1, replaced by getItemCount().

Returns the number of items in this menu.

pack-priv final int
pack-priv void
pack-priv int
public AccessibleContext

Returns:

an AccessibleAWTMenu that serves as the AccessibleContext of this Menu
getAccessibleContext
()

Overrides java.awt.MenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this Menu.

public MenuItem

Returns:

the item located at the specified index.
getItem
(int
the position of the item to be returned.
index
)

Gets the item located at the specified index of this menu.

public int

Returns:

the number of items in this menu
getItemCount
()

Get the number of items in this menu.

pack-priv final MenuItem
getItemImpl(int index)

pack-priv MenuItem
pack-priv boolean
private static native void
initIDs()

Hides java.awt.MenuItem.initIDs.

Initialize JNI field and method IDs

public void
insert(MenuItem
the menu item to be inserted.
menuitem
,
int
the position at which the menu item should be inserted.
index
)

Inserts a menu item into this menu at the specified position.

public void
insert(String
the text on the item
label
,
int
the position at which the menu item should be inserted
index
)

Inserts a menu item with the specified label into this menu at the specified position.

public void
insertSeparator(int
the position at which the menu separator should be inserted.
index
)

Inserts a separator at the specified position.

public boolean

Returns:

true if this is a tear-off menu; false otherwise.
isTearOff
()

Indicates whether this menu is a tear-off menu.

public String

Returns:

the parameter string of this menu
paramString
()

Overrides java.awt.MenuItem.paramString.

Returns a string representing the state of this Menu.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.MenuItem.readObject.

Reads the ObjectInputStream.

public void
remove(int
the position of the item to be removed.
index
)

Removes the menu item at the specified index from this menu.

public void
remove(MenuComponent
the item to be removed from the menu. If item is null or is not in this menu, this method does nothing.
item
)

Implements java.awt.MenuContainer.remove.

Removes the specified menu item from this menu.

public void
removeAll()

Removes all items from this menu.

public void
removeNotify()

Overrides java.awt.MenuComponent.removeNotify.

Removes the menu's peer.

pack-priv synchronized Enumeration<MenuShortcut>
private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Hides java.awt.MenuItem.writeObject.

Writes default serializable fields to stream.

Inherited from java.awt.MenuItem:
addActionListenerdeleteShortcutdisabledisableEventsdoMenuEventenableenableenableEventseventEnabledgetActionCommandgetActionCommandImplgetActionListenersgetLabelgetListenersgetShortcutisEnabledprocessActionEventprocessEventremoveActionListenersetActionCommandsetEnabledsetLabelsetShortcut

Field Detail

baseback to summary
private static final String base

Hides java.awt.MenuItem.base.

isHelpMenuback to summary
pack-priv volatile boolean isHelpMenu

This field will be set to true if the Menu in question is actually a help menu. Otherwise it will be set to false.

itemsback to summary
private final Vector<MenuItem> items

A vector of the items that will be part of the Menu.

See Also
countItems()
nameCounterback to summary
private static int nameCounter

Hides java.awt.MenuItem.nameCounter.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.MenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
tearOffback to summary
private final boolean tearOff

This field indicates whether the menu has the tear of property or not. It will be set to true if the menu has the tear off property and it will be set to false if it does not. A torn off menu can be deleted by a user when it is no longer needed.

See Also
isTearOff()

Constructor Detail

Method Detail

addback to summary
public MenuItem add(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:MenuItem

the menu item to be added

Returns:MenuItem

the menu item added

See Also
java.awt.Menu#insert(java.lang.String, int), java.awt.Menu#insert(java.awt.MenuItem, int)
addback to summary
public void add(String label)

Adds an item with the specified label to this menu.

Parameters
label:String

the text on the item

See Also
java.awt.Menu#insert(java.lang.String, int), java.awt.Menu#insert(java.awt.MenuItem, int)
addNotifyback to summary
public void addNotify()

Overrides java.awt.MenuItem.addNotify.

Creates the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

addSeparatorback to summary
public void addSeparator()

Adds a separator line, or a hyphen, to the menu at the current position.

See Also
java.awt.Menu#insertSeparator(int)
constructComponentNameback to summary
pack-priv String constructComponentName()

Overrides java.awt.MenuItem.constructComponentName.

Construct a name for this MenuComponent. Called by getName() when the name is null.

countItemsback to summary
public int countItems()

Deprecated

As of JDK version 1.1, replaced by getItemCount().

Returns the number of items in this menu.

Returns:int

the number of items in this menu

Annotations
@Deprecated
countItemsImplback to summary
pack-priv final int countItemsImpl()
deleteShortcutback to summary
pack-priv void deleteShortcut(MenuShortcut s)

Overrides java.awt.MenuItem.deleteShortcut.

getAccessibleChildIndexback to summary
pack-priv int getAccessibleChildIndex(MenuComponent child)

Overrides java.awt.MenuComponent.getAccessibleChildIndex.

Defined in MenuComponent. Overridden here.

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.MenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.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.

Returns:AccessibleContext

an AccessibleAWTMenu that serves as the AccessibleContext of this Menu

Since
1.3
getItemback to summary
public MenuItem getItem(int index)

Gets the item located at the specified index of this menu.

Parameters
index:int

the position of the item to be returned.

Returns:MenuItem

the item located at the specified index.

getItemCountback to summary
public int getItemCount()

Get the number of items in this menu.

Returns:int

the number of items in this menu

Since
1.1
getItemImplback to summary
pack-priv final MenuItem getItemImpl(int index)
getShortcutMenuItemback to summary
pack-priv MenuItem getShortcutMenuItem(MenuShortcut s)

Overrides java.awt.MenuItem.getShortcutMenuItem.

handleShortcutback to summary
pack-priv boolean handleShortcut(KeyEvent e)

Overrides java.awt.MenuItem.handleShortcut.

initIDsback to summary
private static native void initIDs()

Hides java.awt.MenuItem.initIDs.

Initialize JNI field and method IDs

insertback to summary
public void insert(MenuItem menuitem, int index)

Inserts a menu item into this menu at the specified position.

Parameters
menuitem:MenuItem

the menu item to be inserted.

index:int

the position at which the menu item should be inserted.

Exceptions
IllegalArgumentException:
if the value of index is less than zero
Since
1.1
See Also
java.awt.Menu#add(java.lang.String), java.awt.Menu#add(java.awt.MenuItem)
insertback to summary
public void insert(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:String

the text on the item

index:int

the position at which the menu item should be inserted

Exceptions
IllegalArgumentException:
if the value of index is less than zero
Since
1.1
See Also
java.awt.Menu#add(java.lang.String), java.awt.Menu#add(java.awt.MenuItem)
insertSeparatorback to summary
public void insertSeparator(int index)

Inserts a separator at the specified position.

Parameters
index:int

the position at which the menu separator should be inserted.

Exceptions
IllegalArgumentException:
if the value of index is less than 0.
Since
1.1
See Also
java.awt.Menu#addSeparator
isTearOffback to summary
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:boolean

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

paramStringback to summary
public String paramString()

Overrides java.awt.MenuItem.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.

Returns:String

the parameter string of this menu

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException, HeadlessException

Hides java.awt.MenuItem.readObject.

Reads the ObjectInputStream. Unrecognized keys or values will be ignored.

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if the class of a serialized object could not be found
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless, writeObject(ObjectOutputStream)
removeback to summary
public void remove(int index)

Removes the menu item at the specified index from this menu.

Parameters
index:int

the position of the item to be removed.

removeback to summary
public void remove(MenuComponent item)

Implements java.awt.MenuContainer.remove.

Removes the specified menu item from this menu.

Parameters
item:MenuComponent

the item to be removed from the menu. If item is null or is not in this menu, this method does nothing.

removeAllback to summary
public void removeAll()

Removes all items from this menu.

Since
1.1
removeNotifyback to summary
public void removeNotify()

Overrides java.awt.MenuComponent.removeNotify.

Removes the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

shortcutsback to summary
pack-priv synchronized Enumeration<MenuShortcut> shortcuts()
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides java.awt.MenuItem.writeObject.

Writes default serializable fields to stream.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to write

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
See Also
AWTEventMulticaster#save(ObjectOutputStream, String, EventListener), readObject(ObjectInputStream)
java.awt back to summary

protected Class Menu.AccessibleAWTMenu

extends AccessibleAWTMenuItem
Class Inheritance
Known Direct Subclasses
java.awt.PopupMenu.AccessibleAWTPopupMenu

Inner class of Menu used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

This class implements accessibility support for the Menu class. It provides an implementation of the Java Accessibility API appropriate to menu user-interface elements.

Since
1.3

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.awt.MenuItem.AccessibleAWTMenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Constructor Summary

AccessConstructor and Description
protected
AccessibleAWTMenu()

Constructs an AccessibleAWTMenu.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleRole.

Get the role of this object.

Inherited from java.awt.MenuItem.AccessibleAWTMenuItem:
doAccessibleActiongetAccessibleActiongetAccessibleActionCountgetAccessibleActionDescriptiongetAccessibleNamegetAccessibleValuegetCurrentAccessibleValuegetMaximumAccessibleValuegetMinimumAccessibleValuesetCurrentAccessibleValue

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.MenuItem.AccessibleAWTMenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Annotations
@Serial

Constructor Detail

AccessibleAWTMenuback to summary
protected AccessibleAWTMenu()

Constructs an AccessibleAWTMenu.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object