0

I am playing around with some styles and ran into something I cant seem to find an answer for. I created a custom TableCellRenderer and overrode getTableCellRenderComponent, basically just changing the background color:

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean    isSelected, boolean hasFocus, int row, int col) {
    Component l = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    l.setBackground(Color.LIGHT_GRAY);
    return l;
}

My problem is that when i call this to change say my table header background color, it removes the tables grid lines

table.getColumnModel().getColumn(k).setHeaderRenderer(newCustomTableCellRenderer());

Not sure why this is happening. How to fix it?

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
3uPh0riC
  • 440
  • 1
  • 4
  • 16

1 Answers1

3

As @MadProgrammer notes, "The border is supplied by the look and feel specific header." You can obtain a copy of the UI delegate's renderer, as shown here and here, and decorate it as desired. A related example using common defaults is seen here.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974