Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: Menu [javadoc | source]
java.lang.Object
   java.awt.MenuComponent
      java.awt.MenuItem
         java.awt.Menu

All Implemented Interfaces:
    MenuContainer, Accessible, Serializable

Direct Known Subclasses:
    PopupMenu

A Menu object is a pull-down menu component that is deployed from a menu bar.

A menu can optionally be a tear-off menu. A tear-off menu can be opened and dragged away from its parent menu bar or menu. It remains on the screen after the mouse button has been released. The mechanism for tearing off a menu is platform dependent, since the look and feel of the tear-off menu is determined by its peer. On platforms that do not support tear-off menus, the tear-off property is ignored.

Each item in a menu must belong to the MenuItem class. It can be an instance of MenuItem, a submenu (an instance of Menu), or a check box (an instance of CheckboxMenuItem).

Nested Class Summary:
protected class  Menu.AccessibleAWTMenu  Inner class of Menu used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

This class implements accessibility support for the Menu class. It provides an implementation of the Java Accessibility API appropriate to menu user-interface elements. 

Field Summary
 Vector items    A vector of the items that will be part of the Menu. 
 boolean tearOff    This field indicates whether the menu has the tear of property or not. It will be set to true if the menu has the tear off property and it will be set to false if it does not. A torn off menu can be deleted by a user when it is no longer needed. 
 boolean isHelpMenu    This field will be set to true if the Menu in question is actually a help menu. Otherwise it will be set to false.
    serial:
 
Fields inherited from java.awt.MenuItem:
enabled,  label,  actionCommand,  eventMask,  actionListener
Fields inherited from java.awt.MenuComponent:
peer,  parent,  appContext,  font,  newEventsOnly,  actionListenerK,  itemListenerK,  accessibleContext
Constructor:
 public Menu() throws HeadlessException 
    Constructs a new menu with an empty label. This menu is not a tear-off menu.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    since: JDK1.1 -
 public Menu(String label) throws HeadlessException 
    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, or in another menu of which this menu is a submenu.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
 public Menu(String label,
    boolean tearOff) throws HeadlessException 
    Constructs a new menu with the specified label, indicating whether the menu can be torn off.

    Tear-off functionality may not be supported by all implementations of AWT. If a particular implementation doesn't support tear-off menus, this value is silently ignored.

    Parameters:
    label - the menu's label in the menu bar, or in another menu of which this menu is a submenu.
    tearOff - if true, the menu is a tear-off menu.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    since: JDK1.0. -
Method from java.awt.Menu Summary:
add,   add,   addNotify,   addSeparator,   constructComponentName,   countItems,   countItemsImpl,   deleteShortcut,   getAccessibleChildIndex,   getAccessibleContext,   getItem,   getItemCount,   getItemImpl,   getShortcutMenuItem,   handleShortcut,   insert,   insert,   insertSeparator,   isTearOff,   paramString,   remove,   remove,   removeAll,   removeNotify,   shortcuts
Methods from java.awt.MenuItem:
addActionListener,   addNotify,   constructComponentName,   deleteShortcut,   deleteShortcut,   disable,   disableEvents,   doMenuEvent,   enable,   enable,   enableEvents,   eventEnabled,   getAccessibleContext,   getActionCommand,   getActionCommandImpl,   getActionListeners,   getLabel,   getListeners,   getShortcut,   getShortcutMenuItem,   handleShortcut,   isEnabled,   paramString,   processActionEvent,   processEvent,   removeActionListener,   setActionCommand,   setEnabled,   setLabel,   setShortcut
Methods from java.awt.MenuComponent:
constructComponentName,   dispatchEvent,   dispatchEventImpl,   eventEnabled,   getAccessControlContext,   getAccessibleChildIndex,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getFont,   getFont_NoClientCode,   getName,   getParent,   getParent_NoClientCode,   getPeer,   getTreeLock,   paramString,   postEvent,   processEvent,   removeNotify,   setFont,   setName,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.Menu Detail:
 public MenuItem add(MenuItem mi) 
    Adds the specified menu item to this menu. If the menu item has been part of another menu, removes it from that menu.
 public  void add(String label) 
    Adds an item with the specified label to this menu.
 public  void addNotify() 
    Creates the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.
 public  void addSeparator() 
    Adds a separator line, or a hypen, to the menu at the current position.
 String constructComponentName() 
    Construct a name for this MenuComponent. Called by getName() when the name is null.
 public int countItems() 
Deprecated! As - of JDK version 1.1, replaced by getItemCount().

 final int countItemsImpl() 
  void deleteShortcut(MenuShortcut s) 
 int getAccessibleChildIndex(MenuComponent child) 
    Defined in MenuComponent. Overridden here.
 public AccessibleContext getAccessibleContext() 
    Gets the AccessibleContext associated with this Menu. For menus, the AccessibleContext takes the form of an AccessibleAWTMenu. A new AccessibleAWTMenu instance is created if necessary.
 public MenuItem getItem(int index) 
    Gets the item located at the specified index of this menu.
 public int getItemCount() 
    Get the number of items in this menu.
 final MenuItem getItemImpl(int index) 
 MenuItem getShortcutMenuItem(MenuShortcut s) 
 boolean handleShortcut(KeyEvent e) 
 public  void insert(MenuItem menuitem,
    int index) 
    Inserts a menu item into this menu at the specified position.
 public  void insert(String label,
    int index) 
    Inserts a menu item with the specified label into this menu at the specified position. This is a convenience method for insert(menuItem, index).
 public  void insertSeparator(int index) 
    Inserts a separator at the specified position.
 public boolean isTearOff() 
    Indicates whether this menu is a tear-off menu.

    Tear-off functionality may not be supported by all implementations of AWT. If a particular implementation doesn't support tear-off menus, this value is silently ignored.

 public String paramString() 
    Returns a string representing the state of this Menu. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
 public  void remove(int index) 
    Removes the menu item at the specified index from this menu.
 public  void remove(MenuComponent item) 
    Removes the specified menu item from this menu.
 public  void removeAll() 
    Removes all items from this menu.
 public  void removeNotify() 
    Removes the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.
 synchronized Enumeration shortcuts()