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 ;
}
}

你可能感兴趣的:(object,table,null,Class)