e810. 创建弹出菜单

 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
posted @ 2018-09-06 08:54  borter  阅读(129)  评论(0编辑  收藏  举报