943,604 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2021
  • Java RSS
May 22nd, 2009
0

public Component getTableCellRendererComponent() method problem

Expand Post »
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.
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Encryption algorithme problem
Next Thread in Java Forum Timeline: conway's game of life help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC