I have a Jtable which gets populated from an array of values. My code is like this:
private static final String[] columnNames = {\"Line Number\", \"Error\"
You can create a custom cell renderer. In its implementation, check if percentage value is > 30 for a given row, then highlight this cell.
For example:
class SomeRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component c = super.getTableCellRendererComponent(table,
value, isSelected, hasFocus, row, column);
if (isHighlightingEnabled){
Integer percentage = (Integer) table.getValueAt(row, 3);
if (percentage > 30)
c.setBackground(Color.RED);
}
return c;
}
}
You may enable/disable this rendering logic upon action if needed.
See Using Custom Renderers for more details.