我有一个 JTree 显示我自己的 TreeModel。 TreeModel 是从数据库“按需”加载的(有点难看,因为部分是在 EDT 上完成的,但这不是我的问题)。有一个菜单允许用户选择要应用于树的过滤器。
更改过滤器时,TreeModel 可能会隐藏节点,或者可能会显示新节点。这就是我的问题所在 - 我看不到从模型生成适当的 treeStructureChanged 事件的合理方法,因为我不知道哪些节点真正发生了变化。似乎没有简单的方法可以告诉听众整个模型现在(可能)不同了。
有没有一种简单的方法告诉所有 TreeModelListeners 整个模型已更改? (当然我想尽可能保留选择/扩展状态)。
I have a JTree displaying my own TreeModel. The TreeModel is loaded "on demand" from a database (somewhat ugly since partially done on the EDT, but thats not my issue here). There is a menu which will allow the user to select a filter to be applied to the tree.
When changing the filter, nodes may be hidden by the TreeModel or new nodes may be revealed. This is where my problem lies - I see no reasonable way of generating the appropiate treeStructureChanged events from the model, since I have no idea which nodes really have changed. There seems to be no simple way of telling the listeners that the entire model is now (potentially) different.
Is there a simple way of telling all TreeModelListeners that the entire model has been changed? (Of course I want to retain selection/expansion state as far as possible).
发布评论
评论(1)
因为您想要表明整个树结构已更改,所以发送
TreeModelEvent
用于每个侦听器的树根。GenealogyModel
方法fireTreeStructureChanged()
是如何使用树:创建数据模型< /a>.Because you want to signal that the entire tree structure has changed, send a
TreeModelEvent
for the tree's root to each listener. TheGenealogyModel
methodfireTreeStructureChanged()
is an example mentioned in How to Use Trees: Creating a Data Model.