Quillion
Quillion

Reputation: 6476

Different grid color for different columns

How would I go about setting different grid color for different columns?

I know that table.setGridColor(Color.GREEN); sets the grid color to specific color, but what about setting color for every line?

I would like my table to have every odd column grid color red and every even column grid color green.

Just go vie an example I want the following

G____R____G____R____G
|____|____|____|____|
|____|____|____|____|
|____|____|____|____|
|____|____|____|____|

Where R means that the line should be colored red and G means that the line should be colored Green.

This is just for fun and Christmas spirit.

Thanks to anyone for their help.

The only possible solution I can think of is creating a custom
TableCellRenderer
and within method
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
doing
setBorder(new MatteBorder(0, 0, 0, 1, Color.RED));
for every odd column and
setBorder(new MatteBorder(0, 0, 0, 1, Color.GREEN));
for every even column.

Upvotes: 0

Views: 728

Answers (1)

camickr
camickr

Reputation: 324128

Check out Table Row Renderering for examples that show how to override the prepareRenderer(...) to highlight the background of different row.

The concept would be similar for column level rendering.

Upvotes: 3

Related Questions