tags:

views:

247

answers:

1

Currently, I'm using a custom TreeCellRenderer to handle label and icon changes for my JTree. The problem comes when I need to change the text on a few nodes. The TreeCellRenderer works great in that the new text is displayed. However, the width from the initial text is cached and is not updated. I've attempted to hack it by overriding getPreferredSize in the TreeCellRenderer but that's not working properly since I have html strings. I've even tried parsing out the tags and getting the width, but it's still not perfect. I've used SwingUtilities, and FontMetrics.

It seems that using the tree's backing DefaultTreeModel.nodeChanged(TreeNode) is the proper way to change a node. However, I would need to have an additional data structure to handle accessing the nodes that need to be changed. Personally, I would like to only change the nodes that need changing. But, that would require another data structure to find all nodes that need to be updated kinda thing. What's the best way around the size caching of the backing JLabel in this situation?

A: 

I've found that using the way you suggested of calling nodeChanged has worked best for me.

Jeff Storey