Hi
I have a program that finds duplicate files and lists them in a Jtable. I have modified the default Table Renderer to change the colour of the cells but I want them to have more than two colours. Say Blue for the first set of say 5 files all of which are duplicates of each other, then the next three say green and all of which are duplicates again of each other but different to the first five. Naturally I do not know how many of the duplicates of each file exist nor do I know the values in either of the cells or rows.
I wrote a renderer but it changes all the rows to one colour defeating my purpose.
public class MyTableRenderer extends DefaultTableCellRenderer
{
public MyTableRenderer()
{
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
{
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
return this;
}
public void blue()
{
setBackground(Color.blue);
}
public void red()
{
setBackground(Color.red);
}
}
in the class from which the rows are added I have a vector that reads 1 set of duplicates and enters a loop to start adding to the Jtable. Here I change I call the MytableRenderer.Blue() method. My logic as seen below:
if (colour == true)
{
renderer.blue();
colour = false;
}
else
{
renderer.red();
colour = true;
}
duplicates.addElement(r.elementAt(i));
for(int x=0;x<duplicates.size();x++)
{
addToTable(((File)duplicates.elementAt(x)));
}
duplicates.clear();[/ICODE]
Is this the right way or am I wrong?
Many thanks