This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Proper way of resizing JTree cells on changing node text

 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I searched through the forum for the answer, I read several comments, but I still don't know what is the proper way to get a JTree resize it's elements. I have a JTree with each node having custom user object. This object can change so the result of it's toString() can also change. I also use a custom TreeCellRenderer which extends DefaultTreeCellRender and sets the node's icon and tooltip text based on the custom user object. The problem occures whenever the new text is wider than the previous one, in this case the items in the tree will be cropped, since no resize happens on them.
Can anybody explain me the proper(or at least a good) way of doing this.
Thanks in advance,
Miklós
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trigger a TreeModel.treeNodesChanged event.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. In my case every custom user object change its state individually on some kind of event. Is this mean that I have to store a reference to the JTree(or at least to the data model) and to the TreeNode which contains my data in order to call treeNodesChangedEvent?

P.S.: I tried it with storing the references, and it's workig, but it has a side effect, it closes the childnode group. Can I prevent it somehow?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic