Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help! JTable and TableCellRenderer color problem

 
James Hare
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
If anyone can PLEASE help I would greatly appreciate it.
Basically, I'm trying to set the background color of a cell in a column of a JTable based on it's value. BUT, when I use this, sometimes a cell will not get it's appropriate color correctly. Most notably, the first line does not seem to update correctly with the new color unless I drag a selection over it and then release it. It's as if the color choice from other columns is bleeding over to this column. Also, scrolling the scrollbar (JScrolPanel) using the arrows at the ends causes odd painting and bleeding to occur.
I am using JBuilder 5.0 as my IDE, but can duplicate this using the standard jdk 1.3.1
Here's some code nuggets. This is the interface I use to set up my generic cell color chooser...

And here is the renderer:

And here is the actual color picker I am using:

And the place I add it to the table:

The AlignmentTableCellRenderer is simply another renderer that aligns the text right-justified.
 
James Hare
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, to make matters more interesting, if I change my highlighter to a DefaultTableCellRenderer and set the colors on the setValue call instead (as follows), the problem goes away! Has anyone else had issues with using getTableCellRendererComponent or chaining renderers together?
Here's my new renderer:
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I haven't. I will look at your getTableCellRendererComponent(). It doesn't look quite right to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic