JTable and Icon for Checkbox

Hi,

I have a JTable. Some of the Columns are boolean. With my TableModel these boolean values are displayed as checkboxes.

What I want now, is having an Icon (or whatever Image) instead of the checkbox. Each Column should have a different icon.

What I did, was writing a custom CellRenderer. This worked fine for displaying, but in Editormode there are Problems.

I would like to change the properties of the standard checkbox, that the table uses, or replace it with a custom checkbox. (how can I access the standard checkbox?)

Has anyone done this before?

[600 byte] By [rebelman] at [2007-9-26 1:55:28]
# 1

You will have to write a custom editor. You can get the base code from DefaultTableCellEditor. In the editor you instantiate a check box exactly the way you want it to appear in the table and then return the check box as the editor component. If you want a different icon for each cell, you will have to have a switch-type statement in your editor so

if(row == 0 && col == 0)

icon ==x

else if(row == 0 && col ==1)

icon == y

etc

then add that icon to your checkbox model.

You can also make a separate editor for each cell but that gets a little more complicated but is on the same idea

alsues at 2007-6-29 3:09:24 > top of Java-index,Archived Forums,Swing...