开发者

Swing JTree: It seems to be impossible to properly send treeStructureUpdated events to model listeners

开发者 https://www.devze.com 2023-03-17 05:20 出处:网络
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 wi

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 tellin开发者_如何学Gog all TreeModelListeners that the entire model has been changed? (Of course I want to retain selection/expansion state as far as possible).


Because you want to signal that the entire tree structure has changed, send a TreeModelEvent for the tree's root to each listener. The GenealogyModel method fireTreeStructureChanged() is an example mentioned in How to Use Trees: Creating a Data Model.

0

精彩评论

暂无评论...
验证码 换一张
取 消