13.23. Pop-up Menus

Pop-up menus are remarkably simple to use: allocate a PopupMenu, add some MenuItems to it, then watch for the pop-up trigger in a Component by checking mouse events with isPopupTrigger. When the trigger is received, call show to display the menu. When the menu is shown, an ActionEvent is triggered for a selected menu item.

Constructors

The two PopupMenu constructors are:

public PopupMenu()

public PopupMenu(String title)

The first constructor creates an untitled pop-up menu. The second constructor creates a pop-up menu with the specified title. However, most current Windows 95/98/NT implementations do not display the title.

Example: Applet Pop-up Menu

Listing 13.43 creates a pop-up menu in an applet. It then watches the mouse ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

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