Hey thanks for replying.
With code like that:
public class yellowCellRenderer
extends DefaultTableCellRenderer
{
private int whichRow = 0;
public yellowCellRenderer(int saveToRow)
{
this.whichRow = saveToRow;
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if(this.whichRow == row){
this.setBackground(Color.YELLOW); // All columns verified were empty - set our background RED
}
return this;
}
}
and usage:
comments.add(comment);
JTable table = getMainTable();
TableColumnModel colModel = table.getColumnModel();
for(int i=0;i<comment.length;i++){
if(!Main.isStringEmpty((String)comment[i])){
TableColumn column = colModel.getColumn(i);
column.setCellRenderer(
new yellowCellRenderer(table.getRowCount()-1)
);
}
}
Every each cell in column gets yellow background... What am I doing wrong?>
Because the render object is reused for each cell in the column, you need
to comprehensively set its properties every time. Say:
if(this.whichRow == row){
this.setBackground(Color.YELLOW);
} else {
this.setBackground(table.getBackground());
}