> I made a jTable and add columns to it. One column is a checkbox column. I
> made an editor and a renderer to it, but it doesn't work very well.
> If I check in the checkbox in the last row and then click to an other cell
> then all checkbox will be checked in.
Impossible to say exactly without more code.
> public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer
> {
>
> public CheckBoxRenderer() {
> setOpaque(false);
Use setContentAreaFilled. Is it not the default?
> }
>
> public Component getTableCellRendererComponent(
> JTable table, Object value,
> boolean isSelected, boolean hasFocus,
> int row, int column) {
> if (value != null) {
> this.setSelected( ( (Boolean) value).booleanValue());
Do not leave the check box at its old state if 'value' is 'null'.
Either null is invalid, then remove the 'if', or null should be
treated as one of true/false.
If false (as usual), this can be written without casting:
this.setSelected(Boolean.TRUE.equals(value));
(this will also allow other Objects then Booleans and treat them all as
false).
Christian
> Hello,
> then all checkbox will be checked in.
May be you reused the identical value object in different table cells? The
renderer is ok.