java treemodel怎么_java – 当TreeModel添加新节点时,为什么我的JTree不能更新?

我使用的DefaultTreeModel填充了DefaultMutableTreeNode的覆盖,它支持可选地更改树中节点的显示字符串.如下面的代码所示,在我的表单中,我通过在一个单独的类中创建它们然后通过我的主数据类型的包装类传递它们来为新节点填充树.其中的过程是创建一个新的重写的DefaultMutableTreeNode,向其添加子节点(每个AccessPoint由具有多个子节点的节点表示),然后将其存储以供以后在UI中使用.

我第一次以这种方式添加节点,它工作得很漂亮.添加了以下代码的任何后续节点实际上存储在DefaultTreeModel中,但JTree未使用新节点进行更新.

为什么在添加第一个孩子后,JTree没有填充?

private void populateAccessPointTreeModel(AccessPointDataWrapper wrapper) {

//the pre-created DefaultMutableTreeNode subclass instance is

// stored in the wrapper

DefaultMutableTreeNode accessPointNode =

wrapper.getAccessPointTreeNode();

//this line updates the accessPointTree with the new node (I've looked at the

// value in debug mode, and it does in fact add the node

((DefaultMutableTreeNode) accessPointTree.getRoot()).add(accessPointNode);

//unrelated logic happens down here...

}

我可以在必要时包含我创建节点的代码,但我不认为这是问题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值