problem with TableCellRenderer
Table got painted properly but the method 慻etTableCellRendererComponent?is getting called on every event like mouse click,minimize or maximize the screen and changing the color patterns.
How can we restrict to call 慻etTableCellRendererComponent?only once at first !
=======================================================
private TableRenderer2 tr = new TableRenderer2();
TableColumn tc = null;
for (int c = 0; c < T_Data.getColumnCount(); c++) {
if (c != 3) {
tc = this.T_Data.getColumnModel().getColumn(c);
tc.setCellRenderer(tr);
}
}
=======================********======================
class TableRenderer2 extends DefaultTableCellRenderer implements TableCellRenderer{
private String preVal = null;
private int i=0;
private boolean firstTime = true;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = null;
cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (firstTime) {
if (value != null && column==0 && !isSelected && !hasFocus) {
if (preVal != null && value != null && !isSelected && !hasFocus) {
if (preVal.equalsIgnoreCase(value.toString())) {
cell.setForeground(cell.getForeground());
cell.setBackground(cell.getBackground());
} else {
if (i == 0) {
cell.setForeground(Color.GREEN);
cell.setBackground(Color.BLACK);
i=1;
} else {
cell.setForeground(Color.YELLOW);
cell.setBackground(Color.BLACK);
i=0;
}
}
} else if (!isSelected && !hasFocus) {
cell.setForeground(Color.YELLOW);
cell.setBackground(Color.BLACK);
}
preVal = (String) value;
}
if (row+1 == table.getRowCount()){
coloring(false);
}
}
// Allow superclass to return rendering component.
return cell;
}
protected void setValue(Object value) {
super.setValue(value);
return;
}
public void coloring(boolean firstTime) {
this.firstTime = firstTime;
}
}

