Hi all,
I have a problem with a Checkbox in a JTable.
When i add the Checkbox into the JTable it displays the String
representation of the Checkbox, which is not what i want.
So, i created a CheckBoxRenderer which extens Checkbox and implements
TableCellRenderer. This seems to have done the job, in that the Checkbox
is displayed and not the String representation. But, and it's a big
'but', the column that holds the Checkbox continually updates the
fields. I cannot select the Checkbox and i can only just see that the
correct info for the Checkbox is in the cell.
I think it has something to do with repainting the Checkbox, but i can't
figure out how to stop it from happening.
Many thanx.
Ben
Here is some of the code, the bit's i think are relevent:
All code is at:
http://www.users.on.net/benmunday/Label/
public class CheckBoxRenderer extends Checkbox implements TableCellRenderer
{
....
public Component getTableCellRendererComponent(JTable table, Object
cBox, boolean isSelected, boolean hasFocus, int row, int column)
{
Checkbox newCheckbox = (Checkbox)cBox;
newCheckbox.setState(false);
return newCheckbox;
}
}
JTable itemDataTable = new JTable(new MyTableModel(data));
itemDataTable.setDefaultRenderer(data[0][0].getClass(),
new CheckBoxRenderer());
itemDataScrollPane.getViewport().setView(itemDataT able);
itemDataScrollPane.setVisible(true);
contentPane.add(itemDataScrollPane, BorderLayout.CENTER);