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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.