Popup Menus

Incredible as it may seem, popup menus were nowhere to be found in the original AWT. As a result, many developers implemented their own popups, but since such popups were drawn entirely in Java code and not implemented by a peer, the native look-and-feel was lost. Fortunately, this deficiency was remedied in the 1.1 version of the AWT with the introduction of a peer-based popup menu.

Popup menus are extremely easy to use. In this section, we'll discuss creating popups, displaying them, and handling the events they generate.

Popups and Components

Popup menus must be attached to an AWT component. In fact, java.awt.Component has two methods for attaching and removing popup menus:

  • add(PopupMenu popup)

  • remove(MenuComponent popup)

Creating ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.