By subclassing JTable to override prepareRenderer, you can adjust the cell renderer and it rendering component any way you like. Here I make individual cells with odd data darker, but you could just as easily have you effect constant across a give row...
Is subclassing the only way to accomplish this? I am using NetBeans 5.0 and so need to add the JTable subclass to a palette and then drag it on to the GUI. Its ok onto the palette but after that .....
You can iterate through the TableColumns, and for each column set the TableCellRenderer you want to use. It's been years since I last used custom renderers (Java 1.1/Swing 1.1.1 timeframe), but back then they slowed down graphics tremendously.
Originally posted by Ulf Dittmer: You can iterate through the TableColumns, and for each column set the TableCellRenderer you want to use. It's been years since I last used custom renderers (Java 1.1/Swing 1.1.1 timeframe), but back then they slowed down graphics tremendously.
The trouble with custom TableCellRenderers in this example (getting foreground color to depend on the data in a row) is that you typically have different types of data in different columns (simple strings, numbers, dates, currency, etc...) so you'll need to define different custom TableCellRenderers for different types of data and that's too much work. Overriding that one JTable method cuts accross renderers and does what you need to do.
The subclassing method worked fine thanks. Adding it to the palette in Netbeans 5.0 (a jolly fine free IDE) was the problem but all solved now thanks again.