我遇到了这样的麻烦。我有一个覆盖数据库结构并使用 JTree 来显示项目。这是我对模型的简化视图:
public class MenuTreeModel implements TreeModel {
private MenuList ml;
public MenuTreeModel( MenuList ml ) {
this.ml = ml;
}
@Override
public void addTreeModelListener(TreeModelListener l) {
}
@Override
public Object getChild(Object parent, int index) {
if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
return ((MenuList) parent).getStation(index);
}
if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
return ((MenuStations) parent).get(index);
}
return null;
}
@Override
public int getChildCount(Object parent) {
if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
return ((MenuList) parent).getSize();
}
if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
return ((MenuStations) parent).getSize();
}
return 0;
}
@Override
public int getIndexOfChild(Object parent, Object child) {
if ( parent.getClass().hashCode() == MenuList.class.hashCode() ){
return ((MenuList) parent).getIndexOf((MenuStations) child);
}
if ( parent.getClass().hashCode() == MenuStations.class.hashCode() ){
return ((MenuStations) parent).getIndexOf((MenuCats) child);
}
return 0;
}
@Override
public Object getRoot() {
return ml;
}
@Override
public boolean isLeaf(Object node) {
return node.getClass().hashCode() == MenuCats.class.hashCode();
}
@Override
public void removeTreeModelListener(TreeModelListener l) {
// TODO Auto-generated method stub
}
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
// TODO Auto-generated method stub
}
当我从ml或其内部项目中删除某些内容时,树结构不会改变。我找不到像fireTreeModelChanged这样的方法。