JTable custom grid line painting

In my JTable, I need to change the appearance of the line between two cells (either making it into a dashed line or just changing the color, the latter probably being easier). I am currently planning to turn off the JTable's grid lines and paint my own grid lines with a custom TableCellRenderer. Does anyone have a better suggestion, or a guide on a good way to do what I'm trying to accomplish? Thanks.

[413 byte] By [aadwighta] at [2007-11-27 11:27:30]
# 1

No I don't have another suggestion, but I do think your solution is the right choice :)

DikkeDouwea at 2007-7-29 16:16:33 > top of Java-index,Desktop,Core GUI APIs...
# 2

The table grid is painted in the BasicTableUI.paintGrid which is unfortunately a private method. However, you can do the following:

1. Use JTable.setGridColor API to change the color

2. Override the JTable.paintComponent and set a custom stroke before calling the super implementation. Here the assumption is that the core implementation doesn't change the stroke (which it doesn't in JDK 5.0). Not the cleanest way to do this, but it should work. Don't forget to restore the old stroke when you're done in paintComponent.

kirillga at 2007-7-29 16:16:33 > top of Java-index,Desktop,Core GUI APIs...