home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Menu

Name

Menu

[Graphic: Figure from the text]

Description

The Menu class represents a group of MenuItem objects. Menus themselves are menu items, allowing you to build multi-level menus. Menus are always attached to MenuBars, which currently can only belong to frames.

Class Definition

public class java.awt.Menu
    extends java.awt.MenuItem
    implements java.awt.MenuContainer {
  
  // Constructors
  public Menu(); (New)
  public Menu (String label);
  public Menu (String label, boolean tearOff);
  
  // Instance Methods
  public synchronized MenuItem add (MenuItem item);
  public void add (String label);
  public void addNotify();
  public void addSeparator();
  public int countItems(); (Deprecated)
  public MenuItem getItem (int index);
  public int getItemCount(); (New)
  public void insert (String label, int index); (New)
  public synchronized void insert (MenuItem menuitem, int index); (New)
  public void insertSeparator (int index); (New)
  public boolean isTearOff();
  public String paramString();  (New)
  public synchronized void remove (int index);
  public synchronized void remove (MenuComponent component);
  public synchronized void removeAll(); (New)
  public void removeNotify();
}

Constructors

Menu

public Menu() (New)

Description

Constructs a Menu object.

public Menu (String label)

Parameters

label

Text that appears on Menu.

Description

Constructs a Menu object with the given label.

public Menu (String label, boolean tearOff)

Parameters

label

Text that appears on Menu.

tearOff

true to create a tear-off menu, false otherwise.

Description

Constructs a Menu object; this will be a tear-off menu if tearOff is set to true.

Instance Methods

add

public synchronized MenuItem add (MenuItem item)

Parameters

item

A MenuItem to add to the Menu.

Returns

Item just added.

Description

Adds a new item to a Menu.

public void add (String label)

Parameters

label

Text for a MenuItem

Description

Constructs a new MenuItem object with the given label, and adds it to a Menu.

addNotify

public void addNotify()

Overrides

MenuItem.addNotify()

Description

Creates a Menu peer, and peers for all MenuItem objects that appear on it.

addSeparator

public void addSeparator()

Description

Adds a separator bar to the Menu.

countItems

public int countItems() (Deprecated)

Returns

The number of items on the menu. Replaced by getItemCount().

getItem

public MenuItem getItem (int index)

Parameters

index

The position of the MenuItem to fetch; the first item has index 0.

Returns

The MenuItem at the designated position.

getItemCount

public int getItemCount() (New)

Returns

The number of items on the menu.

insert

public void insert (String label, int index) (New)

Parameters

label

The label for the new item.

index

The position for the new item.

Description

Adds a new item to this menu.

public synchronized void insert (MenuItem menuitem, int index) (New)

Parameters

menuitem

The item to add.

index

The position for the new item.

Throws

IllegalArgumentException

If index is less than zero.

Description

Adds a new item to this menu.

insertSeparator

public void insertSeparator (int index) (New)

Parameters

index

The position for the separator.

Throws

IllegalArgumentException

If index is less than zero.

Description

Adds a separator to this menu.

isTearOff

public boolean isTearOff()

Returns

true if the menu is a tear-off menu, false otherwise.

paramString

public String paramString() (New)

Returns

String with current settings of Menu.

Overrides

MenuItem.paramString()

Description

Helper method for toString() to generate string of current settings.

remove

public synchronized void remove (int index)

Parameters

index

The position of the MenuItem to remove.

Description

Removes an item from the Menu.

public synchronized void remove (MenuComponent component)

Parameters

component

The element to remove.

Implements

MenuContainer.remove()

Description

Removes an item from the Menu.

removeAll

public synchronized void removeAll() (New)

Description

Removes all items from the Menu.

removeNotify

public void removeNotify()

Description

Destroys Menu peer, and peers for all MenuItem objects that appear on it.

See Also

Frame, MenuComponent, MenuContainer, MenuItem, String


Previous Home Next
MediaTracker Book Index MenuBar

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java