check的jtable

来源:互联网 发布:ping不涉及的网络协议 编辑:程序博客网 时间:2024/06/18 06:30
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;
}
}
原创粉丝点击