Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Menu

Constructors , Methods

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.


Constructors


Menu

public Menu(String  label) 

Constructs a new menu with the specified label. This menu is not a tear-off menu.

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

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

Return Value:

Returns the menu item added.

ParameterDescription
mi the menu item to be 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.

ParameterDescription
label the text on the item


addNotify

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 .


addSeparator

public void addSeparator() 

Adds a separator line to this menu at the current position.


countItems

public int countItems() 

Return Value:

Returns the number of elements in this menu.


getItem

public MenuItem getItem(int  index) 

Return Value:

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

ParameterDescription
index the position of the item to be returned


isTearOff

public boolean isTearOff() 

Return Value:

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.

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

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



Top© 1996 Sun Microsystems, Inc. All rights reserved.