wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTree, CheckBox, Programmatically Checking CheckBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree, CheckBox, Programmatically Checking CheckBox" Watch "JTree, CheckBox, Programmatically Checking CheckBox" New topic

JTree, CheckBox, Programmatically Checking CheckBox

Kirt Cathey

Joined: Oct 29, 2010
Posts: 3
Hi All.

Searched high and low for this but couldn't figure it out.....
I am using this http://www.jroller.com/santhosh/date/20050610 code to create a JTree with checkboxes. All is cool, except when I load nodes into the tree I need to programmatically set the check
on the checkbox nodes. Any ideas on how to do this?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37902
Welcome to the Ranch

What about the setSelected(boolean) method? Have you found that?
Kirt Cathey

Joined: Oct 29, 2010
Posts: 3
With the code that I referred to in the original posting, there are check boxes in the manager and the renderer.

Which one to setSelected with?
When I expose either one and setSelected, nothing changes on the tree.

Repaint issue?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
did you try posting a comment (question) on the blog?
did you try emailing the author of the code?
Kirt Cathey

Joined: Oct 29, 2010
Posts: 3
No and No.... the posting was from 2005. After some thorough reading and much trial and error, I learned a bit about cell renderer. But it look's like there is more than one way to make this happen.
Here is the code I ended up with... but didn't use check boxes - opted for status markers instead.

Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

Please UseCodeTags next time. I've added them for you this time.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: JTree, CheckBox, Programmatically Checking CheckBox
Similar Threads
Code for JTree with checkbox
Dynamic checkbox JTree
JTree with CheckBox
JTree in Browser