Hat tip to some previous online implementations (each has a different implementation):
Bare bones
With a TreeCellEditor
More recent variations
After a couple of iterations of checkbox trees (and tree tables), I rolled this up into a standalone
TreeCellRenderer
so that it can be applied more easily to any tree-oriented component. This implementation also properly handles rollover effects on the checkbox, which is lacking in the above implementations (most visible under w32; Java's Metal LAF has no checkbox rollover effects).The checkbox painting is handled by using a real checkbox and painting its contents into an icon. The state of the checkbox is set just prior to painting to ensure the proper rollover state. The original cell renderer's icon is replaced with a composite icon of the original plus the checkbox (hit ^-shift-O to switch component orientation).
The renderer provides the current checked selection as an array of
TreePath
or an array of int
representing the rows. I also applied this to my own tree table implementation (similar to SwingX
JXTreeTable
) by just overriding a few protected methods which translate mouse coordinates into rows/paths.Source
10 comments:
Hi,
I have also posted similar stuff in my weblog long back;
JTree with CheckBoxes:
http://www.jroller.com/page/santhosh/20050610#jtree_with_checkboxes
CheckTree with/without Selection Digging
http://jroller.com/page/santhosh?entry=checktree_with_without_selection_digging
Show CheckBoxes only on specific Tree Nodes
http://www.jroller.com/page/santhosh?entry=show_checkboxes_only_on_specific
JXTreeTable with CheckBoxes
http://www.jroller.com/page/santhosh/20050614#jxtreetable_with_checkboxes
Thank u sir for what your doing it is helping a lot to improve our coding skills
thank u
What is the License under which we can use this code.
This code is licensed under LGPL. It will shortly be available in code repository at http://furbelow.sf.net.
Thanks for your reply. I tried your renderer and it works great. thanks. But I will not be able to use it unless the code has the LGPL license comment in it. So do you have any idea when the code will be posted in the website you metioned with the license comment ?
Thanks again.
Should be done within a week.
oh my, i've been searching forever for such a piece of code. thx so much!!
best wishes, manunu
Hi technomage,
first of all I'd like to thank you for this post, it is just what I've been looking for (for quite a while).
But I also have a request:
Would you be so kind to provide a jar-file containing the updated version of the source including the license comment? Also, please do not use the default package as you have done in the first version of your jar.
See, I want to use your renderer in a commercial project and can only do so without touching my own license if I import your renderer as a library (hence the need for a jar).
In addition, since Java 1.5 it is not possible anymore to access classes that are in the default package from a named package. And that is why I can't use your older jar (apart from the missing license comment).
So I need your renderer in a jar with the license comment in a named package, can you do that please?
Best Regards,
Lostprophet
You have permission to use the code under the BSD license if you wish.
That's great, thank you very much!
Post a Comment