Hi All,
I have a class that has a Boolean field in it. I display in a JTable a list of of those classes. I created a CustomCellRenderer to change the background color of the rows, so I could have different colors.
the problem: when the customrenderer is applied on the Boolean field, (true/false) is rendered instead of the default renderer's checkbox.
how can I have both features: background colors and checkbox?
here is the customrenderer code:
public class CustomCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object obj,boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, obj,isSelected, hasFocus, row, column);
if (isSelected) {
cell.setBackground(Color.red);
} else {
if (row % 2 == 0) {
cell.setBackground(new Color(110,134,214));
} else {
cell.setBackground(Color.lightGray);
}
}
return cell;
}
}
thanks in advance for any help.