怎么能让用右键选中树的节点?就像左键选中的效果一样,这样就可以直接用右键选树的节点并直接出菜单了谢谢

解决方案 »

  1.   

    mousePressed
    xt_JTree.setSelectionPath(xt_JTree.getPathForLocation(
    me.getX(), me.getY()));
    mouseReleased
    popupMenu.show(this, me.getX(), me.getY());
      

  2.   

    在树的mouseClicked事件中写://获取选中的节点
            TreePath path = this.treDate.getPathForLocation(e.getX(), e.getY());
            //选中节点
            this.treDate.setSelectionPath(path);
            //得到当前节点
            DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) path.
                    getLastPathComponent();
    //
    //弹出右键菜单
            if (e.getButton() == 3&&e.getClickCount() == 1) {//鼠标右键且单击
                    this.pmTree.show(this.treDate, e.getX(), e.getY());
            }