![]() ![]() |
![]() |
![]() ![]() ![]() ![]() |
![]() |
This document briefly describes the API for MenuItems in Swing. This document briefly describes the JMenuItem class, which is used to create menu bars in Swing. Comprehensive documentation for the Swing menu system is currently under development. For general information about menus and how they work in the Menu system as a whole, see the specification titled The Swing Menu System. Consult the menu-related JavaDoc APIs for current details.
In AWT 1.1.x, MenuItem was a subclass of MenuComponent, which was subclassed directly from Object. This architecture meant that improvements to Component and Container were not automatically reusable in MenuItem, but first had to be duplicated in MenuComponent.
This was necessary in 1.1.x because menus were based on native controls, which in many cases place severe limitations on MenuItems. In the Swing toolkit, implementing JMenu and JMenuItem as lightweight component classes frees us from many of these limitations. For instance, we can now decide to add any type of component to a menu.
A JMenuItem is basically a button on a popup menu. This arrangement provides a look and feel that is slightly different from a non-menu button. Because most applications have a common idea of what a JMenuItem's look and feel should be, it makes sense to include this class in the toolkit to support consistency across applications. This strategy also provides a common point for defining the look and feel for consistency with the native toolkits.
Features of the Swing JMenuItem API include the following:
The goals for the Swing JMenuItem design were:
The following methods are included in the JMenuItem API:
The following method is deprecated in the MenuItem API:
The following methods were inherited from Button asf are no longer needed:

Version 0.5. Last modified 10/1/97.
Copyright © 1995-97 Sun
Microsystems, Inc. All Rights Reserved.