Show 'expand' control on JTree nodes after children are removed?
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?
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
精彩评论