package ca.sqlpower.swingui; import java.awt.Component; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; /** * A renderer for presenting a JCheckBox in a JTable cell. It makes sure the check box * looks right (correct foreground and background colour depending on the cell's selection * state) in the table. */ public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { public CheckBoxRenderer() { setHorizontalAlignment(JLabel.CENTER); } 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()); } setSelected((value != null && ((Boolean) value).booleanValue())); return this; } }