Hello Frank,

2 solutions:

1. In your subclass of JTable include the code looking something like this:

 public Component prepareRenderer(TableCellRenderer renderer,
                                         int rowIndex, int vColIndex) {
            Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
            if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
                c.setBackground(Color.yellow);
            } else {
                // If not shaded, match the table's background
                c.setBackground(getBackground());
            }
            return c;
        }

This will color every second column yellow.
Advantage: Works for every kind of cell renderer (Text, number, date,
custom renderes etc.).
Disadvantage: You have to subclass JTable

2. Make your own version of a TableCellRenderer and put the logic in
there.

Advantage: You do not need to subclass JTable
Disadvantage: It will only change the color for those cells which have
your cellrenderer. e.g. you need to manually install them.
        
Friday, May 10, 2002, 2:25:40 AM, you wrote:

Frank> [the saga of my re-enty into the GUI world continues...]

Frank> I need to set the row color for my subclass of JTable.
Frank> All the example code that I've discovered show how to
Frank> change the color of a *column*.

Frank> I thought it would be as easy as:

Frank>         x = get the TableCellRenderer for that row,col
Frank>         c = get the Component for that TableCellRenderer
Frank>         c.setForeground(Color.foo)
Frank>         c.setBackground(Color.bar)

Frank> But nope...  And I've tried Googling for examples, but nothing
Frank> useful.  Seems pretty obtuse just to change the color of
Frank> a row...

Frank> Any help out there is appreciated.

Frank> Frank G.
Frank> +======================================================================+
Frank> | Crossroads Technologies Inc, 55 Broad Street, 28th Fl, NYC, NY 10004 |
Frank> |  Enterprise Java Engineering                                         |
Frank> | Email: [EMAIL PROTECTED]         Web: www.CrossroadsTech.com |
Frank> | Voice: 212-482-5280 x229                 Fax: 212-482-5281           |
Frank> +======================================================================+


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



-- 
Best regards,
 Max                            mailto:[EMAIL PROTECTED]

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

Reply via email to