> Just to explain the question further. When the row is selected,
> the dafault
> selection color overwrites the color set by the setForeground method in my
> custom cell renderer.

Providing that you have subclassed DefaultTableCellRenderer, you should be
able to call setForeground() in your getTableCellRendererComponent() method
*after* calling super. Remember, it is this method in
DefaultTableCellRenderer that initializes the colors and fonts of the label
each time every cell is renderered:

// Not tested for compilability...
class MyRenderer extends DefaultTableCellRenderer
{
  public Component getTableCellRendererComponent(....)
  {
    super.getTableCellRendererComponent(...);// inits colors, fonts, etc.
based on table properties
    setForeground(myColor);
    return this;
  }
}

The code for DefaultTableCellRenderer is not complex. Take a look and you
should be able to figure it out.

------------------------------
David Zeleznik
Project Manager, Gantt R&D
ILOG JViews Team
mailto:[EMAIL PROTECTED]
http://www.ilog.com
------------------------------



> -----Original Message-----
> From: Reinstein, Lenny
> Sent: Thursday, March 14, 2002 1:38 PM
> To: [EMAIL PROTECTED]
> Subject: Row Selection color in JTable
>
>
> I know we can set the selection color for all rows in the table:
>
> table.setSelectionForeground( Color.white );
> table.setSelectionBackground( Color.red );
>
> I would like to be able to set the foreground color of specific rows. My
> goal is when I change the foreground color of a particular row
> based on some
> logic, I want that foreground color to be the same when the row
> is selected.
> Is there a way to do it?
>
> Thanks!
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
>

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to