| | |
public Component getTableCellRendererComponent() method problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 60
Reputation:
Solved Threads: 0
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.
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.
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.
![]() |
Similar Threads
- virtual void method() = 0; problem (C++)
- Simple JTable Data Issue (Java)
- cannot explain the arrayIndexOutofBoundsException (Java)
- Changing the colour of rows in Jtable (Java)
- how to set fix size to button cell (Java)
- using the setText() method - getting error cannot find symbol (Java)
- JTable Cell Renderers (Java)
Other Threads in the Java Forum
- Previous Thread: Encryption algorithme problem
- Next Thread: conway's game of life help
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet component csv database doctype draw ebook eclipse encode error event exception file fractal freeze game givemetehcodez graphics gui helpwithhomework html ide image input integer intellij iphone j2me java java.xls javaprojects jmf jni jpanel julia linux list loop loops mac map method methods mobile netbeans newbie number online oracle page parameter print problem program programming project recursion reporting rotatetext scanner screen server set size sms socket sort sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working





