aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Proper way of resizing JTree cells on changing node text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Proper way of resizing JTree cells on changing node text" Watch "Proper way of resizing JTree cells on changing node text" New topic
Author

Proper way of resizing JTree cells on changing node text

Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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

Joined: Oct 27, 2005
Posts: 19794
    
  20

Trigger a TreeModel.treeNodesChanged event.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Proper way of resizing JTree cells on changing node text