
The column variable holds the column index on which our formatting is based on. In our case the "Indexes" column is the 11th column so we use a value of 10 as the column numbering starts at "0"
 
Next we assign, the two alternating colors
color1 = Color.red;
color2 = Color.blue;
 
You may use the following color values Color.black, Color.green, Color.cyan etc. Here is a list of default colors
 
If the default colors are not enough then you may specify new colors by providing the RGB values such as
color1 = new Color(102,34,140);
color2= new Color(222,39,89);
 
 
If you need similar result then you don't have to modify the script further but if you need anything different then you may modify the script to suit your purpose.
 
Here is the complete script
 
column=10; //for the 1st col use 0, second use 1....11th column use 10 ( n-1)
Color color1=Color.red;
Color color2=Color.blue;
//if (colIndex==column)
{
 
if ( rowIndex==0) //if the series is just starting then this variable will be null
{
prevColor=0; //set the initial color to red
prevRowIndex=rowIndex;
 
 
}
 
// if (isNumeric) //the current cell is numeric value
{
if (rowIndex==0)
{
if (prevColor==0) renderer.setForeground(color1);
else renderer.setForeground(color2);
//prevValue=value;
}
else
{
 
prevValue= table.getValueAt(rowIndex-1,column);
colValue=table.getValueAt(rowIndex,column);
if ( !(prevValue.toString().equals(colValue.toString() )) ) //previous row is different than the current row
{
 
if (prevRowIndex!=rowIndex) //if it is a different row then try to change the color
{
if (prevColor==0) prevColor=1;
else if (prevColor==1) prevColor=0;
}
 
}
if (prevColor==0) renderer.setForeground(color1);
else renderer.setForeground(color2);
//////////////////////////////////////////////////////
if (table.isCellSelected(rowIndex,colIndex))
{
renderer.setForeground(Color.white);
renderer.setBackground(Color.blue);
}
/////////////////////////////////////////////////////
prevRowIndex=rowIndex;
// prevValue=value;
}
 
}
}