This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree, CheckBox, Programmatically Checking CheckBox" Watch "JTree, CheckBox, Programmatically Checking CheckBox" New topic
Author

JTree, CheckBox, Programmatically Checking CheckBox

Kirt Cathey
Greenhorn

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?

--Kirt
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Welcome to the Ranch

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

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
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
JTree with CheckBox
JTree in Browser