I have Checkbox in JTable Header, I am using Nimbus L&F and customize the header background but the background of the checkbox takes the default grey background not the customize one as others column do.
Following is the CheckboxRenderer class
public class CheckBoxHeader extends JCheckBox implements TableCellRenderer{
public CheckBoxHeader(ItemListener itemListener) {
addItemListener(itemListener);
setHorizontalAlignment(SwingConstants.CENTER);
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JTableHeader header = table.getTableHeader();
Color bg = header.getBackground();
setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue()));
return this;
}
And in Table
TableColumn tc = getColumnModel().getColumn(0);
tc.setCellEditor(getDefaultEditor(Boolean.class));
tc.setCellRenderer(getDefaultRenderer(Boolean.class));
((JComponent)getDefaultRenderer(Boolean.class)).setOpaque(true);
tc.setHeaderRenderer(new CheckBoxHeader());
AFAIK to get the proper rendering of the header it should render with DefaultTableCellRenderer but i am not getting the way for it. Any suggestions?
I’m not so sure if it work on all LnF(testing only Windows 7, Java 1.7.0_03):