checkのjtable


JTable table 
=
 
new
 JTable();
TableColumn col
= table.getColumn(columnName);
col.setCellEditor(
new DefaultCellEditor( new JCheckBox()));
col.setCellRenderer(
new MyCheckBoxRenderer());
// Renderer
public class MyCheckBoxRenderer
extends JCheckBox
implements TableCellRenderer {

public MyCheckBoxRenderer() {}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected,
boolean hasFocus,
int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
}
else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}
if (value == null || ! (value instanceof Boolean)) {
value
= new Boolean( false );
}
setSelected( ( (Boolean) value).booleanValue());
return this ;
}
}