3uPh0riC
3uPh0riC

Reputation: 490

Java Swing Custom TableCellRenderer loses its Grid lines

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?

Upvotes: 1

Views: 606

Answers (1)

trashgod
trashgod

Reputation: 205865

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.

Upvotes: 3

Related Questions