O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required