| Author |
Setting foreground of a table cell on date column
|
Jennifer Sohl
Ranch Hand
Joined: Feb 28, 2001
Posts: 455
|
|
How do I set the foreground of a cell that is of the date column class in my renderer? I've tried But it doesn't seem to work. Something else interesting... I tried doing the following: and nothing ever prints to std out. Any ideas why?? What am I missing? Thanks! [ August 21, 2003: Message edited by: Jennifer Sohl ]
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
|
How are you setting this renderer on your table?
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Jennifer Sohl
Ranch Hand
Joined: Feb 28, 2001
Posts: 455
|
|
I am using the following:
|
 |
Jennifer Sohl
Ranch Hand
Joined: Feb 28, 2001
Posts: 455
|
|
I just tried something else in my renderer: I added the following code: Nothing ever printed out, like the column wasn't ever equal to index 9??? The same thing happens on columns of Integer type. If the column is a String , it prints out. Here's my model: Here's my renderer: Here is how I am setting the renderer: What's going on??? Many thanks to anyone that can help! [ August 22, 2003: Message edited by: Jennifer Sohl ]
|
 |
VIJAY Yadlapati
Ranch Hand
Joined: Aug 04, 2003
Posts: 175
|
|
Try with this code public class GeneralRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if(column == <Date Column No> { setFont(<font> ; setBackground(<BackgroundColor> ; setForeground(<ForegroundColor> ; } return this; } }
|
 |
VIJAY Yadlapati
Ranch Hand
Joined: Aug 04, 2003
Posts: 175
|
|
Try with this code public class GeneralRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if(column == <Date Column No> { setFont(<font> ; setBackground(<BackgroundColor> ; setForeground(<ForegroundColor> ; } return this; } }
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
|
JTables use the most specific renderer they can... they already have a default renderer for String, Integer, Boolean, etc. so they are never going to use your renderer if you register it with the java.lang.Object class. You're going to have to set your renderer as the default renderer for the String.class, the java.util.Date.class, and anything else your renderer is providing a view for.
|
 |
Jennifer Sohl
Ranch Hand
Joined: Feb 28, 2001
Posts: 455
|
|
Thanks for all the help. I tried setting the default renderer for each class String, Integer and Date, and it is working now. Funny, I've never run into that before. Guess you learn something new every day!! Thanks again!
|
 |
 |
|
|
subject: Setting foreground of a table cell on date column
|
|
|