当我尝试从JTreeTable中删除所选节点时,我遇到了一个奇怪的错误。 首先,我从JXtreeTable
中获取主类中的选定行table.getSelectedRow()
我使用此方法执行此操作,并返回正确的行数。 但随后,狗屎发生了。 在我的模型类中,我调用方法delete children:
package JTreeTable;
import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
import org.jdesktop.swingx.treetable.MutableTreeTableNode;
import org.jdesktop.swingx.treetable.TreeTableModel;
public class TableModel extends DefaultTreeTableModel implements TreeTableModel {
DefaultMutableTreeTableNode root;// = new DefaultMutableTreeTableNode("Root");
public TableModel(DefaultMutableTreeTableNode root){
super(root);//it didnt work without this line. it took me a day to figure it out. I hate my life sometimes.
this.root = root;
}
public int getColumnCount()
{
return 4;
}
@Override
public String getColumnName( int column )
{
switch( column )
{
case 0: return "Description";
case 1: return "Amount";
case 2: return "Date";
case 3: return "Paid";
default: return "Unknown";
}
}
public void addChildren(){
int rootChildCount = root.getChildCount();
ArrayNode newChild = new ArrayNode(new Object[] {"dfds", "sfddsf","dfsfsd","fdsfsd"});
this.insertNodeInto(newChild, root, rootChildCount);
}
public void removeChildren(int index){
//root.remove(index);
System.out.println(root.getChildCount());
}
}
这是我的节点类:
package JTreeTable;
import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
public class ArrayNode extends DefaultMutableTreeTableNode {
public ArrayNode(Object[] data) {
super(data);
}
@Override
public Object getValueAt(int column) {
return getUserObject()[column];
}
@Override
public void setValueAt(Object aValue, int column) {
getUserObject()[column] = aValue;
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public Object[] getUserObject() {
return (Object[]) super.getUserObject();
}
@Override
public boolean isEditable(int column) {
return true;
}
}
因此,当我使用方法root.remove(index)时,我总是会收到错误" Node必须是由此模型管理的有效节点"。但我很确定我的节点没问题!这意味着什么并且可以解决?
答案 0 :(得分:1)
您正在尝试直接从另一个节点删除子节点,绕过TreeTableModel。使用DefaultTreeTableModel.removeNodeFromParent,例如:
depositfiles-porn.ga|youporn-forum.ga|pornhub-forum.ga|generalporn.org|rapidgator-porn.ga|meendo-free-traffic.ga|amanda-porn.ga|torture.ml|pornhub-forum.uni.me