开发者

Show 'expand' control on JTree nodes after children are removed?

开发者 https://www.devze.com 2023-03-17 16:05 出处:网络
I have a DefaultTreeModel containing a subclass of DefaultMutableTreeNode. I have only overridden isLeaf() to always return true because I lazily load the children when the node is expanded. Then, whe

I have a DefaultTreeModel containing a subclass of DefaultMutableTreeNode. I have only overridden isLeaf() to always return true because I lazily load the children when the node is expanded. Then, when the node is collapsed, I remove the children (firing the proper treeNodesRemoved event) because I have unsubscribed from updates from the server.

The problem is that after the user collapses a node and I remove the children, the stupid little expand circle disappears (but clicking that area still works to expand the node). How ca开发者_Python百科n I always show the expand control when the children have been removed?

Related: Add 'expand' button to JTree node that has no children?. Is adding a fake child the only way?

Show 'expand' control on JTree nodes after children are removed?


The way I did it is I add a fake child and expansion listener when children are removed. When I get notification that the node with fake child is going to be expanded I replace the fake child with actual lazily loaded children.

This way the node always has children and expand control is always presented

0

精彩评论

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

关注公众号