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;
}

