I want to color specific cells at the same time from a jtable
For example, the cells with column = 1
and row i+2
(i from 0 to 5 ).
I successfully colored a specific cell using a CustomTableCellRenderer
like the example show
public class CustomTableCellRenderer extends DefaultTableCellRenderer
{
int x;
int y;
CustomTableCellRenderer(int x,int y){ //constructor
this.x= x;
this.y=y;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column)
{
Component cell = super.getTableCellRendererComponent
(table, value, isSelected, hasFocus, row, column);
if ( ((row == x) && (column == y))) { //test of equivalence of x and y as parameter
cell.setBackground(Color.green);
}
else {
cell.setBackground(Color.WHITE);
}
return cell;
}
}