Packages  This Package  Prev  Next  Index  

§1.29 Class Menu

public  class  java.awt.Menu
    extends  java.awt.MenuItem  (II-§1.32)
    implements java.awt.MenuContainer  (II-§1.44)
        // Constructors
    public Menu(String  label);	§1.29.1
    public Menu(String  label, boolean  tearOff);	§1.29.2

        // Methods
    public MenuItem add(MenuItem  mi);	§1.29.3
    public void add(String  label);	§1.29.4
    public void addNotify();	§1.29.5
    public void addSeparator();	§1.29.6
    public int countItems();	§1.29.7
    public MenuItem getItem(int  index);	§1.29.8
    public boolean isTearOff();	§1.29.9
    public void remove(int  index);	§1.29.10
    public void remove(MenuComponent  item);	§1.29.11
    public void removeNotify();	§1.29.12
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(II-§1.32). This can be an instance of MenuItem, a submenu (an instance of Menu), or a check box (an instance of CheckboxMenuItem (II-§1.7)).

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.
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.
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.
mi - the menu item to be added
the menu item 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.
label - the text on the item


public void addNotify()
This method calls the createMenu method (II-§1.41.14) of this object's toolkit (II-§1.10.20) in order to create a MenuPeer (II-§3.16) 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.
addNotify in class MenuItem (II-§1.32.2).


public void addSeparator()
Adds a separator line to this menu at the current position.


public int countItems()
the number of elements in this menu.


public MenuItem getItem(int index)
index - the position of the item to be returned
the item located at the specified index of this menu.


public boolean isTearOff()
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.
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.
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.
removeNotify in class MenuComponent (II-§1.31.7).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to