JTable Setting Background color for multiple rows based on condition
843805Feb 24 2006 — edited May 9 2006Hi an urgent help. I have a JTable with the 1st column as a Checkbox. I need to set the Background color of the entire row if the checkbox is checked. Am using DefaultTableCellRenderer.
int rowCount = table.getRowCount();
for(int i=0 ;i <rowCount ; i++)
{
boolean bFlag = Boolean.valueOf(table.getValueAt(i,0).toString().trim()).booleanValue();
if(bFlag) {
table.setSelectionBackground(Color.red);
}
else {
table.setSelectionBackground(Color.WHITE);
}
}
but the above code sets color only for the currently active row.. whereas i need the same for multiple rows. What should i do?