开发者

Right Click PopupMenus in Java

开发者 https://www.devze.com 2023-03-20 00:14 出处:网络
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 retu
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());
                    }
                }


Which method in MouseListener are you calling this in? Depending on which OS, it may be triggered by mousePressed or mouseReleased so you need to call this from both of those methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消