• 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

JCheckBoxes in JTree nodes

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm fairly new with JTrees and in fact, Java on the whole. I've created a JTree with JCheckBoxes as the nodes. How do you implement listeners on such a component? For eg, can I use an ItemEvent listener for the checkboxes, while using a TreeSelectionListener for the nodes? I want to be able to get the data at the node that was checked, which my tre does right now, but also when the box is deselected, I want to perform some action. Can this be done with an ItemListener on the checkbox??
Please, any assistance is appreciated. It's urgent!
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't think of a reason why you couldn't add an ItemListener to a JCheckBox no matter what its container was. So go for it. By the way if for some reason it doesn't work let us all know.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope I'm wrong, but I think if you set the JComboBox as the Renderer for JTree nodes that's all it is, it tells it how to render. JTree has a different model for Rendering and Selection. But I'm probably wrong about this
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I stand corrected (ran a little test that flopped). I have not had much practical experience with JTrees other than using them as a navigation aid with Strings at the nodes. Unfortunately JTree is not as robust as JTable but I am sure you can accomplish your task if you stay with it. I just fear it may get pretty involved.
I will definitely investigate this further because we're all here to learn.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a mouse listener to your tree node... check and see if the getPoint() of the click falls within the bounds of the check box on the tree node. If so, toggle the check box.

Easy!

-Nate
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey...thanks guys!
I will try the mouseListener and let you know if it works. Do any of you know about a getOldLeadSelectionPath() method?? I read this in another post...it was an option for determining the deselected node.
I will keep you posted.
Thanks again!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic