JTree监听鼠标双击事件

  MouseListener ml = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                int selRow = tree.getRowForLocation(e.getX(), e.getY());
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
                if(selRow != -1) {
                    if(e.getClickCount() == 1) {
                        System.out.println(111);
                    }
                    else if(e.getClickCount() == 2) {
                        System.out.println(222);
                    }
                }
            }
        };

        tree.addMouseListener(ml);
发布了200 篇原创文章 · 获赞 99 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_43889841/article/details/103401549