aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Please Help!  JTable and TableCellRenderer color problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Please Help!  JTable and TableCellRenderer color problem" Watch "Please Help!  JTable and TableCellRenderer color problem" New topic
Author

Please Help! JTable and TableCellRenderer color problem

James Hare
Greenhorn

Joined: Nov 08, 2001
Posts: 5
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.


=========================<BR>Jim Hare<BR>Bank of America<BR>james.m.hare@bankofamerica.com
James Hare
Greenhorn

Joined: Nov 08, 2001
Posts: 5
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

Joined: May 17, 2001
Posts: 2823
No I haven't. I will look at your getTableCellRendererComponent(). It doesn't look quite right to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help! JTable and TableCellRenderer color problem
 
Similar Threads
making a row grey in JTable
JTable + AbstractTableModel
Color in JTable
disabling rows in JTable
JTable Cell Renderer