I have a table which is sortable. There is a column which shows
checkboxes.
Now the requirement is - a Checkbox has to be added to the table
header so that when the checkbox is selected, all the checkboxes in
that column get selected and vice versa.
But if i render the table header with checkbox, i cant add the sort
icon. So i am thinking of having a two line table header - first line
containing the table header text and sort icon, the second line
containing the checkbox.
Can anyone please tell me how this can be done.
Thanks in advance
This is tricky, but is certainly possible. We do this in several of
our applications, adding a text-box to allow for cell filtering on a
column-by-column basis.
Basically, you need to override each column's TableCellRenderer with
one of your own creation. Any component can be returned from the
getTableCellRendererComponent; we return a JPanel containing the JLabel
(for the header) and a JTextBox (for the user input), layed out with a
GridBagLayout.
A tricky aspect of this is interpreting and passing-on mouse clicks.
With a checkbox, this shouldn't be too hard, since you only need to
pass on clicks, and needn't worry about replacing the components in the
header with editors, which we have to do with ours (the JTextBox
becomes a JComboBox when clicked).
To set the TabelCellRenderer, I've overriden the
JTable#addColumn(JTableColumn) method. This works, but I'm sure there
are better ways of doing it.
Hope this helps,
Walter Gildersleeve
Freiburg, Germany
______________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green