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:
panel1
was
selected.
MouseClicked
event was selected and the name panel1_mouseClicked
entered.
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());
}
}
About Menu Terminology
About Menu Components
About the Menu
Editor
Copyright © 1997, 2004, Oracle. All rights reserved.