再问一下,通过节点的名称name,可以得到这个节点的Path么?怎么做?

解决方案 »

  1.   

    too easy look down//添加树选取事件
        tree.addTreeSelectionListener(new TreeSelectionListener()
        {
          public void valueChanged(TreeSelectionEvent event)
          {        //得到选中的树节点
            TreePath path = tree.getSelectionPath();
            if (path == null) return;
            DefaultMutableTreeNode thisnode = (DefaultMutableTreeNode) path.getLastPathComponent();
            //变量定义
            String sql="select EMP_ID,EMP_REALNAME from employee where emp_onjob='1' and emp_dept_id='" ;
            String deptid=getDeptId(thisnode.toString());
            String sqlcondition=deptid+"'";
            Vector userVector=new Vector();
            int size=0;
            String temp="";
            int  rowcount=customModel.getRowCount();
            //先移除表中的所有数据,再添加入新的数据
            for(int i=rowcount;i>0;i--)
            {
              try{
                customModel.removeRow(i-1);
              }
              catch(Exception ex)
              {
                System.out.println(ex.toString());
              }
            }
            //得到人员信息
            try
            {
              userVector=client.getUserDetail(sql,sqlcondition);
            }
            catch(Exception ex)
            {
              System.out.println(ex.toString());
            }
            size=userVector.size();
            for(int j=0;j<size;j++)
            {
              temp=userVector.get(j).toString();
              rowData[0]=getDeptId(temp);
              rowData[1]=getUserId(temp);
              customModel.addRow(rowData);
              //tablemodel
            }
            //userVector.removeAllElements();
          }
        });