Hi
Im trying to change row colors in a JTable but the whole table changes to the same color. Only if I drag and highlight the whole table, the Specific rows im trying to change, show the correct color. I dont understand this, am I forgetting something?
public vRows is a Vector set from the main class and mainTable is a customTable
can I set vRows from the main Class?
/************************************************** *********************/
this is from the main Class in "button_clicked"
Vector vColor = new Vector();
vColor.add(1);
vColor.add(2);
vColor.add(6);
vColor.add(7);
mainTable.vRows = vColor;
mainTable.setModel(model);
mainTable.repaint();
/************************************************** */
public class CustomTable extends JTable {
public Vector vRows;
public CustomTable(int numRows, int numColumns) {
super(numRows, numColumns);
}
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
Component comp = super.prepareRenderer(renderer, row, column);
int i = 0;
while (vRows.size() > (i)){
if (row == vRows.get(i)){
comp.setBackground(Color.LIGHT_GRAY);
}
i++;
}
repaint();
return comp;
}
/************************************************** ********************/
Thanks
Brett