树的选中节点事件是如何实现的?
举个简单例子:例如有A,B两个节点,当选中A节点时,就输出“你选中了A”;当选中B节点时,就输出“选中了B”,能否给出具体代码?

解决方案 »

  1.   

    ....设置节点的id为A、B..
    每个节点都带一个onclick事件,例如clickevent(id)
    function clickevent(id){
     alert("你选中了"+id)
    }
      

  2.   

    LZ说的是swing把  = =
      

  3.   

    我之前写的一个程序涉及了这部分功能的实现,我节选一部分代码给你看一下:tree.addTreeSelectionListener(this);//Add TreeSelectionEvent to the tree
    /**
     * Add TreeSelectionEvent to tree when it is clicked
     * @param tse
     */
    public void valueChanged(TreeSelectionEvent tse) {
    if(tse.getSource()==this){
    //Get the component you select and test whether it's a leaf
    DefaultMutableTreeNode dmtn=
    (DefaultMutableTreeNode)this.getLastSelectedPathComponent();
    if(dmtn.isLeaf()){  //如果选中的是树叶(结点)
                                System.out.println("你选中了" + dmtn.toString());
                    }
    }
    }希望对你有用!
      

  4.   

    多查一下API文档你就知道了,那里面介绍了很多功能的实现。
      

  5.   

    鼠标事件,然后是通过getselectpath获取被当前选择节点的路径