JTable and CellRenderer to change background colors
- From: Christian <sichstre@xxxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 14:09:38 +0200
Hi!
Quick question. I'd like to set the background color for each cell in a JTable separately. Now I've already found out that this can be done using the DefaultTableCellRenderer class, the problem is that whenever I try to set a particular cell, the entire table gets flooded with the new color, because obviously the renderer I set serves the entire table. Now how can I assign one renderer for each cell in my table or is there a more convenient way to change the background colors? In the JAVA API I have a method getCellRenderer(int row, int column), but no method that allows me to set a CellRenderer for a particular cell.
Here's my code snipplet for changing the color at position (x,y):
JTable jt = new JTable (/*blah*/); DefaultTableCellREnderer d; d = (DefaultTableCellRenderer)jt.getCellRenderer(x,y); d.setBackground(Color.GREEN);
Thanks, Chris. .
- Follow-Ups:
- Re: JTable and CellRenderer to change background colors
- From: John McGrath
- Re: JTable and CellRenderer to change background colors
- From: Michael Rauscher
- Re: JTable and CellRenderer to change background colors
- Prev by Date: Re: JTextPane Paste
- Next by Date: Java GUI -v- .NET Winforms ?
- Previous by thread: revalidate() vs. repaint()?
- Next by thread: Re: JTable and CellRenderer to change background colors
- Index(es):
Relevant Pages
|
|