• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Proper way of resizing JTree cells on changing node text

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trigger a TreeModel.treeNodesChanged event.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic