• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting foreground of a table cell on date column

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the following:
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic