![]() ![]() |
![]() |
![]() ![]() ![]() ![]() |
![]() |
A menu is a combination of a JMenuItem and a JPopupMenu. When the JMenuItem portion is selected by the user (in the manner dictated by the look and feel being used), the JPopupMenu is displayed. While a menu is posted, the user can interact with the items on the menu, or can cancel the menu (in the manner designated by the current look and feel).
This document describes the API for menus in Swing. For more information about menus and how they work in the Menu system as a whole, see the specification titled The Swing Menu System.
Swing supports (or will support) the following features of menus:
The model of a menu in Swing is quite simple. It uses the ButtonModel, and in particular uses the Selected flag to indicate whether it specifies the posted state of the menu.
Menus are sources for MenuEvents. When an object has registered itself as a MenuListener on a menu, the object is notified whenever the menu is posted or unposted.
The API for menus is a superset of the 1.1.1 API.
Also note that it is now possible to add an Action to a menu. When you do that, a properly configured MenuItem is generated.
JMenu()
JMenu(String)
JMenu(String, boolean)
void add(String)
void add(JMenuItem)
void add(JMenu)
void add(JAction)
void addSeparator()
void insert(String, int)
void insert(JMenuItem, int)
void insert(JMenu, int)
void insert(JAction, int)
void insertSeparator(int)
void remove(JMenuItem)
void remove(JMenu)
void remove(JAction)
void remove(int)
void removeAll()
MenuItem getItem(int) // How should this be now that other child types exist?
int getItemCount()
boolean isTearOff()
String paramString()
The following new methods are introduced in Swing:
void replaceItem(MenuItem, MenuItem)
void replaceItem(int, MenuItem)
void setLabel(String)
String getLabel()
void addMenuListener(MenuListener)
void removeMenuListener(MenuListener)
The following methods have been removed in Swing:
addNotify()
countItems()
removeNotify()

Version 0.4. Last modified 09/04/97.
Copyright © 1995-97 Sun
Microsystems, Inc. All Rights Reserved.