I have a table with four columns, and I would like each column head to be a different color. I only want the column head to have color, not the rest of the cells in the column. I tried using the DefaultTableCellRenderer, but it made every cell red except for the column heads. What could I change in my code (below) to individually assign a color to each column head?
class CustomRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, 3, 3);
c.setBackground(new java.awt.Color(255,72,72));
return c;
}
}
table.setDefaultRenderer(Object.class, new CustomRenderer());
You can’t set each individual color easily I’m afraid.
This should suit your needs though.