I am looking for how to change the color of some rows in my JTable
which have index in an integer vector called Notfoundrow
, but the problem that I have as result all the rows in the Table change color to Red !!
Here is my code :
package essai_trafficclass;
import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
public class MonCellRenderer extends DefaultTableCellRenderer {
public static ArrayList<Integer> Notfoundrow1 = OneWayRelation.Notfoundrow;
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);
int L = 0;
while (L < Notfoundrow1.size()) {
System.out.println("la valeur du vecteur " + Notfoundrow1.get(L));
if (row == Notfoundrow1.get(L) && column == 1) {
cell.setBackground(Color.RED);
} else if (row == Notfoundrow1.get(L) && column == 1) {
cell.setBackground(Color.RED);
} else {
cell.setBackground(Color.WHITE);
}
L++;
}
return cell;
}
}
And then I Call this class by :
tableM.setDefaultRenderer(Object.class, new MonCellRenderer());
tableM
is the table that i want change the color if its rows.
Thank you for any Help.