• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting foreground of a table cell on date column

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you setting this renderer on your table?
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the following:
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic