Hi,
I have a JTable with a tablecellrenderer I have extended from the defaultTableCellrenderer.
In my Table model on which the table is based, I have an algorithm that searches each cell making comparisons, when it finds rows with similar values, it adds colour A to an arrayindex and continues to add colour A for subsequent rows provided they match the prior. When it finds dissimilar values it adds colour B and continues subsequently until again the value changes. In other words colour distinguishing groups.
I have conducted tests and found that Everything works perfectly here as it should and that the problem is in the cellrenderer.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
ResultsModel rm = (ResultsModel) table.getModel();
if(value instanceof Attribute)
{
Attribute a = (Attribute) value;
Component c = super.getTableCellRendererComponent(table, a.getAttribute(), isSelected, false, row, column);
if(useColourScheme)
{
if(a.getAttribute() == null)
{
c.setBackground(Color.WHITE);
return c;
}
else
{
if(a.isHighlighted())
{
c.setBackground(rm.getColour(row));
System.out.println(row);
}
else
{
c.setBackground(Color.WHITE);
}
return c;
}
}
else
{
c.setBackground(Color.WHITE);
return c;
}
}
return super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
}}
I use the value row as the index to retrieve the colour. It works perfectly for the first Rows upon manifestation of the table and also for all the other rows provided I use the scroll up and down buttons of the scroll bar rather than dragging it with the mouse. This is where the problem is. I printed out the row to see if indeed they correspond with the appropriate index and the answer is no. Is there a way around this. Also the colours Bleed into other cells when scrolling with the mouse.
Sorry I would like to put up all the code but it is So much.
Many thanks.