Hat tip to some previous online implementations (each has a different implementation):
After a couple of iterations of checkbox trees (and tree tables), I rolled this up into a standalone
TreeCellRendererso 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
TreePathor an array of
intrepresenting 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.