by transcend » Sun Sep 10, 2006 12:01 pm
Hi,
I case anyone is looking for a solution to the same requirement, I thought I would pass along my solution.
- The column 0 cell renderer uses a custom component derived from JPanel, containing a JCheckBox and a JLabel. This is sufficient for each entry in the tree to display a check box and label (with icon if desired), but you stull need a way to actually check and uncheck the check box. (A listener on the cell rendered doesn't work because it is used only to paint the cell, and ceases to exist afetrwards.)
- When the cell is rendered, store the location and size of the JCheckBox. The point is in the coordinate space of the containing JPanel. You need to translate it up a couple of parent component levels to the coordinate space of the containing TreeTable.
- Add a mouse listener to the TreeTable to listen for the mouse clicks. When a mouse click is detected, ask the table which cell it occurred in. If the cell is in column 0, then find the corresponding row object, retrieve the coordinates of its check box (stored above), and determine if the click was within the check box. If so, change the check box state and fire the row's change handler to trigger a table repaint.
Regards,
Doug