我要在JTREE中多存储一些数据,于是继承了DefaultMutableTreeNode类
在生成树的时候使用 DefaultMutableTreeNode dmt.add(new DefaultMutableTreeNode() )方法出错,
也知道需要修改add方法,可是就不知道该如何改
代码如下,我自己
class CustTreeNode extends DefaultMutableTreeNode{
private String DepID = null;
private String DepNote = null;
public CustTreeNode(){
super();
}
public CustTreeNode(String DepID, String DepName, String DepNote){
super(DepName);
this.setDepID(DepID);
this.setDepNote(DepNote);
}
public void add(CustTreeNode ctn){ //如何写这个add方法???
super(); //这是错误的……
this.setDepID(ctn.getDepID());
this.setDepNote(ctn.getDepNote());
}
//get、set成员略
}
在生成树的时候使用 DefaultMutableTreeNode dmt.add(new DefaultMutableTreeNode() )方法出错,
也知道需要修改add方法,可是就不知道该如何改
代码如下,我自己
class CustTreeNode extends DefaultMutableTreeNode{
private String DepID = null;
private String DepNote = null;
public CustTreeNode(){
super();
}
public CustTreeNode(String DepID, String DepName, String DepNote){
super(DepName);
this.setDepID(DepID);
this.setDepNote(DepNote);
}
public void add(CustTreeNode ctn){ //如何写这个add方法???
super(); //这是错误的……
this.setDepID(ctn.getDepID());
this.setDepNote(ctn.getDepNote());
}
//get、set成员略
}
add(MutableTreeNode newChild)
从其父节点移除 newChild,并通过将其添加到此节点的子数组的结尾,使其成为此节点的子节点。這是api上的 我感覺你的需求 好像和這個有點差頭~
at javax.swing.tree.DefaultMutableTreeNode.insert(DefaultMutableTreeNode.java:165)
at javax.swing.tree.DefaultMutableTreeNode.add(DefaultMutableTreeNode.java:396)
at CustTreeNode.add(CustTreeNode.java:30)
at MainForm.FormatTree(MainForm.java:103)
at MainForm.<init>(MainForm.java:210)
at MainForm.main(MainForm.java:219)
0
Java Result: 1