Hi,

I have the code as below:

import javax.swing.table.DefaultTableCellRenderer;
import java.text.DecimalFormat;
import java.awt.*;
import javax.swing.JTable;


public class ColoredTableCellRenderer extends DefaultTableCellRenderer{

DecimalFormat formatter=new DecimalFormat("#0.000");

public ColoredTableCellRenderer() {
}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row,int column) {
Component renderer = super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);

if (isSelected){
renderer.setBackground(Color.black);
if (column!=4)
renderer.setForeground(Color.white); renderer.setFont(new Font("Dialog", Font.ITALIC, 11));
}
else{
if (row==0)
renderer.setBackground(new Color(240, 250, 210));
else if (1 == row % 2)
renderer.setBackground(new Color(210, 250, 210));
else
renderer.setBackground(new Color(240, 250, 210));
if (column!=4)
renderer.setForeground(Color.black);
renderer.setFont(new Font("Dialog", Font.PLAIN, 11));
}
return renderer;
}

public void setValue(Object value){

if (value instanceof ColorData) {
ColorData cvalue = (ColorData)value;
setForeground(cvalue.cellForeColor);
setText((cvalue.cellData==null)?"0.000"
: formatter.format(cvalue.cellData));
}
else if (value instanceof Double){
setText((value == null) ? "0.000"
: formatter.format(value));
}

else{
super.setValue(value);
}
}
}

*********************
What should I do if I want to change the background color of that cell if the value is changed?

Thanks in advance.