| | |
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
Views: 722 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for Java
add android api apple applet application arguments array arrays automation bank binary bluetooth chat chooser class classes client code component converter database digit draw eclipse equation error event exception file fractal functiontesting game givemetehcodez graphics gui health helpwithhomework html hyper ide idea image infinite input int integer j2me java javame javaprojects jmf jni jpanel julia linux list loop main map method methods mobile myregfun netbeans newbie nonstatic number object oracle pattern pearl print problem program programming project recursion scanner screen scrollbar server set size sms socket sort spamblocker sql sqlserver string superclass swing test thread threads time transfer tree windows





