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.


Constructors

Menu

public Menu(String label)
Constructs a new menu with the specified label. This menu is not a tear-off menu.
Parameters:
label - the menu's label in the menu bar

Menu

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.
Parameters:
label - the menu's label in the menu bar
tearOff - if true, the menu is a tear-off menu

Methods

add

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.
Parameters:
mi - the menu item to be added
Returns:
the menu item added.

add

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.
Parameters:
label - the text on the item

addNotify

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.
Overrides:
addNotify in class MenuItem (II-§1.32.2).

addSeparator

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

countItems

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

getItem

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

isTearOff

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

remove

public void remove(int index)
Deletes the item at the specified index from this menu.
Parameters:
index - an index in the menu

remove

public void remove(MenuComponent item)
Deletes the specified menu item from this menu. If the item is not part of the menu, nothing happens.
Parameters:
item - the menu component to be removed

removeNotify

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 (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 doug.kramer@sun.com