日期:2014-05-20  浏览次数:20724 次

Jtree 问题,我是hashtable中取得数据 想把它组成一个树结构
hashtable ta=new hashtable();
ta.put("00","root")
ta.put("01","00")
  ta.put("0101","01")
  ta.put("0102","01")
  ta.put("0103","01")
ta.put("02","00")
  ta.put("0201","02")
  ta.put("0202","02")
  ta.put("020201","0202")
  ta.put("020202","0202")
ta.put("03","00")
ta.put("04","00")
ta.put("0301","03")
ta.put("0401","04")
ta.put("0402","04")

Enumeration enumer = ta.keys();
while (enumer.hasMoreElements()) {
  Object key = enumer.nextElement();
  System.out.println(key + "=" + ta.get(key));//遍历hashtable 键值
  if(ta.get(key).equals("root")){
  moduleroot.add(new DefaultMutableTree(key))
  }


}

以上代码只能添加第一个节点
我想要的效果是: 00
  |-01
  | |-0101
  | |-0102
  | |-0103
  |
  |-02
  | |-0101
  | |-0102
  | |-010201
  | |-010202
  |
  |-03
  | |-0301
  |
  |-04
  |-0401
  |-0402

兄弟我苦啊 公司不然动源码 手写啊

------解决方案--------------------
呵呵,楼主swing刚入门,去看看API上JTree添加多级子节点的方法吧