I want the ability to highlight some rows of JTable, depending on the values in the row itself. For example, if the existing qty < reorder level, that row should be highlighted in the JTable.
I know there is a table method tblItems.setSelectionBackground(Color.yellow); that works when the rows are selected, but is there a similar method that doesn’t rely on the rows being selected to have them show in a different color?
public class MyTableCellRenderer implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent
(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Object ob=table.getValueAt(row, column);
if(ob.toString().equals("yes")){
//need to colour the entire row
}
return
}
}
you could use my answer to change the color of the cell. the same technique could be used to apply it to each cell in the row.
This is also example with
prepareRenderer