有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

菜单右键单击Java中的弹出菜单

im trying to get right click menus to come up when they control right click in a JPanel. I researched a bit and was able to develop the code, but for some reason the isPopUpTrigger returns false, any ideas? Thanks!

else if(arg0.getButton() == MouseEvent.BUTTON3 )
            {
                if(controlIsPressed){
                    class PopUpDemo extends JPopupMenu {
                        JMenuItem anItem;
                        public PopUpDemo(){
                            anItem = new JMenuItem("Click Me!");
                            add(anItem);
                        }
                    }
                    if(arg0.isPopupTrigger()){
                        PopUpDemo menu = new PopUpDemo();
                        menu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
                    }
                }

共 (1) 个答案

  1. # 1 楼答案

    你在MouseListener中调用哪个方法?取决于哪个操作系统,它可能由mousePressedmouseReleased触发,因此您需要从这两个方法调用它