Overriding prepareRenderer for JTable problems...

I'm having a problem when I override the prepareRenderer method of the JTable class. I've got a checkbox in the first column (just a Boolean value that JTable renders as a checkbox, really..), and I want the renderer to the background to a light blue color for whichever rows are checked. This code works fine, except that when the String value of a cell contains no data (maybe null, maybe ""?) the TableCellRenderer parameter being passed to prepareRenderer is null. As a result, nothing is rendered for the entire column containing this cell. Does anyone know how I can fix this? Here's the code for my overridden prepareRenderer method:

public Component prepareRenderer(TableCellRenderer renderer,int row,int col){

if (renderer !=null){

Component c = super.prepareRenderer(renderer, row, col);

DefaultTableModel model = this.getModel();

Object value = model.getValueAt(row,0);

if((value !=null) && (value.toString().equals("true"))){

c.setBackground(new Color(230,235,245));

c.setForeground(this.getForeground());

}

else{

c.setBackground(this.getBackground());

c.setForeground(this.getForeground());

}

return c;

}

returnnull;

}

[1890 byte] By [bjb39a] at [2007-11-27 4:40:51]
# 1

Works fine for me on a cell containing a null value. Modify the data in this example to contain a null value:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=613783&start=4

Basically, get rid of the initial if condition and always invoke supper.prepareRenderer(...)

camickra at 2007-7-12 9:52:08 > top of Java-index,Desktop,Core GUI APIs...
# 2
Another problem I'm having is that this code seems to override the default behavior to highlight a row on cell click. Any ideas?
bjb39a at 2007-7-12 9:52:08 > top of Java-index,Desktop,Core GUI APIs...