java.awt

Class Menu

Implemented Interfaces:
Accessible, MenuContainer, Serializable
Known Direct Subclasses:
PopupMenu

public class Menu
extends MenuItem
implements MenuContainer, Serializable

This class represents a pull down or tear off menu in Java's AWT.
See Also:
Serialized Form

Nested Class Summary

protected class
Menu.AccessibleAWTMenu
Basic Accessibility class for Menu.

Nested classes/interfaces inherited from class java.awt.MenuItem

MenuItem.AccessibleAWTMenuItem

Nested classes/interfaces inherited from class java.awt.MenuComponent

MenuComponent.AccessibleAWTMenuComponent

Constructor Summary

Menu()
Initializes a new instance of Menu with no label and that is not a tearoff;
Menu(String label)
Initializes a new instance of Menu that is not a tearoff and that has the specified label.
Menu(String label, boolean isTearOff)
Initializes a new instance of Menu with the specified label and tearoff status.

Method Summary

MenuItem
add(MenuItem item)
Adds the specified item to this menu.
void
add(String label)
Add an item with the specified label to this menu.
void
addNotify()
Creates the native peer for this object.
void
addSeparator()
Adds a separator bar at the current menu location.
int
countItems()
Deprecated. As of JDK 1.1, replaced by getItemCount().
AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this Menu.
MenuItem
getItem(int index)
Returns the item at the specified index.
int
getItemCount()
Returns the number of items in this menu.
void
insert(MenuItem item, int index)
Inserts the specified menu item into this menu at the specified index.
void
insert(String label, int index)
Inserts an item with the specified label into this menu at the specified index.
void
insertSeparator(int index)
Inserts a separator bar at the specified index value.
boolean
isTearOff()
Tests whether or not this menu is a tearoff.
String
paramString()
Returns a debugging string for this menu.
void
remove(int index)
Deletes the item at the specified index from this menu.
void
remove(MenuComponent item)
Removes the specifed item from the menu.
void
removeAll()
Removes all the elements from this menu.
void
removeNotify()
Destroys the native peer for this object.

Methods inherited from class java.awt.MenuItem

addActionListener, addNotify, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, extends EventListener> T[] getListeners, getAccessibleContext, getActionCommand, getActionListeners, getLabel, getShortcut, isEnabled, paramString, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut

Methods inherited from class java.awt.MenuComponent

dispatchEvent, getAccessibleContext, getFont, getName, getParent, getPeer, getTreeLock, paramString, postEvent, processEvent, removeNotify, setFont, setName, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Menu

public Menu()
Initializes a new instance of Menu with no label and that is not a tearoff;
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Menu

public Menu(String label)
Initializes a new instance of Menu that is not a tearoff and that has the specified label.
Parameters:
label - The menu label.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Menu

public Menu(String label,
            boolean isTearOff)
Initializes a new instance of Menu with the specified label and tearoff status.
Parameters:
label - The label for this menu
isTearOff - true if this menu is a tear off menu, false otherwise.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Method Details

add

public MenuItem add(MenuItem item)
Adds the specified item to this menu. If it was previously part of another menu, it is first removed from that menu.
Parameters:
item - The new item to add.
Returns:
The item that was added.

add

public void add(String label)
Add an item with the specified label to this menu.
Parameters:
label - The label of the menu item to add.

addNotify

public void addNotify()
Creates the native peer for this object.
Overrides:
addNotify in interface MenuItem

addSeparator

public void addSeparator()
Adds a separator bar at the current menu location.

countItems

public int countItems()

Deprecated. As of JDK 1.1, replaced by getItemCount().

Returns the number of items in this menu.
Returns:
The number of items in this menu.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Menu. The context is created, if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface MenuItem
Returns:
the associated context

getItem

public MenuItem getItem(int index)
Returns the item at the specified index.
Parameters:
index - the item index.
Returns:
The item at the specified index.
Throws:
ArrayIndexOutOfBoundsException - If the index value is not valid.

getItemCount

public int getItemCount()
Returns the number of items in this menu.
Returns:
The number of items in this menu.

insert

public void insert(MenuItem item,
                   int index)
Inserts the specified menu item into this menu at the specified index. If the index is greater than or equal to the number of items already in the menu, the new item is added as the last item in the menu.
Parameters:
item - The menu item to add (null not permitted).
index - The index of the menu item (>= 0).
Throws:
IllegalArgumentException - if the index is less than zero.
NullPointerException - if item is null.

insert

public void insert(String label,
                   int index)
Inserts an item with the specified label into this menu at the specified index. If the index is greater than or equal to the number of items already in the menu, the new item is added as the last item in the menu.
Parameters:
label - The label of the item to add.
index - The index of the menu item (>= 0).
Throws:
IllegalArgumentException - If the index is less than zero.

insertSeparator

public void insertSeparator(int index)
Inserts a separator bar at the specified index value.
Parameters:
index - The index at which to insert a separator bar.
Throws:
IllegalArgumentException - If the index is less than zero.
ArrayIndexOutOfBoundsException - If the index is otherwise invalid.

isTearOff

public boolean isTearOff()
Tests whether or not this menu is a tearoff.
Returns:
true if this menu is a tearoff, false otherwise.

paramString

public String paramString()
Returns a debugging string for this menu.
Overrides:
paramString in interface MenuItem
Returns:
A debugging string for this menu.

remove

public void remove(int index)
Deletes the item at the specified index from this menu.
Parameters:
index - The index of the item to remove.
Throws:
ArrayIndexOutOfBoundsException - If the index is otherwise invalid.

remove

public void remove(MenuComponent item)
Removes the specifed item from the menu. If the specified component does not exist, this method does nothing.
Specified by:
remove in interface MenuContainer
Parameters:
item - The component to remove.

removeAll

public void removeAll()
Removes all the elements from this menu.

removeNotify

public void removeNotify()
Destroys the native peer for this object.
Overrides:
removeNotify in interface MenuComponent

Menu.java -- A Java AWT Menu Copyright (C) 1999, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.