• Post Reply Bookmark Topic Watch Topic
  • New Topic

Double TreeCellRendering...  RSS feed

 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm trying to do something that I'm not quite sure about. I have a JTree and I want to implement JCheckboxes as the icon for some nodes and JRadioButtons for others - for those that I want to select one value from a group (so these would all be at the same path location). Is it possible to set two cell renderers for a JTree? Or can you tell me how else I should go about doing this? I have all nodes as checkboxes as it is now.
Thanks a lot...I need help quick!!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have one tree cell renderer, but you can make that tree cell renderer decide what to render... so you could have some nodes with check boxes and some with radio buttons...

What you need to do is have some value in the class you are rendering that lets the tree cell renderer know whether to draw the item with a checkbox or with a radio button. The Object value parameter of the paintTreeCellRendererComponent() method is a reference to the object that you are trying to render, so you just need to cast value to an object of it's class type and test it.

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!