e810. 创建弹出菜单

时间:2022-08-21 09:43:51
 final JPopupMenu menu = new JPopupMenu();

    // Create and add a menu item
JMenuItem item = new JMenuItem("Item Label");
item.addActionListener(actionListener);
menu.add(item); // Set the component to show the popup menu
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseReleased(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
});
Related Examples