Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.Menu extends java.awt.MenuItem implements java.awt.MenuContainer { // Constructors public Menu(String label); public Menu(String label, boolean tearOff); // Methods public MenuItem add(MenuItem mi); public void add(String label); public void addNotify(); public void addSeparator(); public int countItems(); public MenuItem getItem(int index); public boolean isTearOff(); public void remove(int index); public void remove(MenuComponent item); public void removeNotify(); }
A menu is a pull-down component of a menu bar.
A menu can optionally be a tear-off menu. A tear-off menu can remain on the screen after the mouse button has been released. The mechanism for tearing off a menu is platform dependent.
Each item in a menu must belong to the MenuItem class. This can be an instance of MenuItem, a submenu (an instance of Menu), or a check box (an instance of CheckboxMenuItem ).
There is no event associated with clicking on a menu item to pull down the menu.
public Menu(String label)Constructs a new menu with the specified label. This menu is not a tear-off menu.
Parameter Description label the menu's label in the menu bar
public Menu(String label, boolean tearOff)Constructs a new menu with the specified label.
If the tearOff argument is true, the menu can be torn off; it can remain on the screen after the the mouse button has been released.
Parameter Description label the menu's label in the menu bar tearOff if true, the menu is a tear-off menu
public MenuItem add(MenuItem mi)Adds the specified menu item to this menu.
If the menu item had been part of another menu, remove it from that menu.
Return Value:
Returns the menu item added.
Parameter Description mi the menu item to be added
public void add(String label)Adds an item with the specified label to this menu. This method creates a menu item to hold the string.
Parameter Description label the text on the item
public void addNotify()This method calls the createMenu method of this object's toolkit in order to create a MenuPeer for this menu. This peer allows the application to change the look of a menu without changing its functionality.
Most applications do not call this method directly.
Overrides:
addNotify in class MenuItem .
public void addSeparator()Adds a separator line to this menu at the current position.
public int countItems()Return Value:
Returns the number of elements in this menu.
public MenuItem getItem(int index)Return Value:
Returns the item located at the specified index of this menu.
Parameter Description index the position of the item to be returned
public boolean isTearOff()Return Value:
Returns true if this is a tear-off menu; false otherwise.
public void remove(int index)Deletes the item at the specified index from this menu.
Parameter Description index an index in the menu
public void remove(MenuComponent item)Deletes the specified menu item from this menu. If the item is not part of the menu, nothing happens.
Parameter Description item the menu component to be removed
public void removeNotify()Notifies the menu to destroy its peer.
This menu also notifies each of its menu items to destroy their peers.
Overrides:
removeNotify in class MenuComponent .