Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable Setting Background color for multiple rows based on condition

843805Feb 24 2006 — edited May 9 2006
Hi 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2006
Added on Feb 24 2006
11 comments
1,178 views