Adding a Popup Menu

Popup menus can be created so they open on a particular UI container. You add the popup menu to the container and create an event handler to specify the user's action that triggers the popup.

To add a popup menu:

  1. Open your UI class in the Java Visual Editor.
  2. Drop a popup menu from the AWT or Swing Containers Component Palette into the Structure window. The Menu Editor appears.
  3. Add one or more menu items to the popup menu.
  4. Expand the UI folder in the Structure window and select the panel or other component whose event you want the popup menu attached to so you can see that component in the Property Inspector. For the following example, panel1 was selected.
  5. In the Property Inspector, click the Events tab and click the desired event value field.
  6. Type the stub name of the event into the event value field and press Enter to create an event-handling method stub in the source code with the supplied name. For the following example, the MouseClicked event was selected and the name panel1_mouseClicked entered.
  7. Edit your event-handler stub to resemble the following:
    	
    	void panel1_mouseClicked(java.awt.event.MouseEvent 
          e) {
          
          panel1.add(popupMenu1);
          if (e.isPopupTrigger()) {
            // Make the PopupMenu visible relative to the current mouse 
            // position in the container.
            popupMenu1.show(panel1, e.getX(), e.getY());
            }
          }        
  8. Add event handlers to the popup menu's menu items as needed for your application.

About Menu Terminology
About Menu Components
About the Menu Editor