JTable and CellRenderer to change background colors



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. .



Relevant Pages

  • Re: Need help with complicated use of count background color of Ce
    ... needing help. ... If using conditional formatting, why not ... >> Need help with complicated use of count background color of Cell ...
    (microsoft.public.excel.programming)
  • Re: Project 2007 Issues
    ... Other columns can be the first column, the formatting will just look funny. ... Cell background color is a new thing for project, ... I noticed when I added the group-by, ...
    (microsoft.public.project)
  • Re: JTable and CellRenderer to change background colors
    ... 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. ... 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. ...
    (comp.lang.java.gui)
  • Re: colorindex = xlnone on condition of month of year
    ... Henry, I fixed my problem. ... to have the background color change to "no color". ... >>> Dim rng As Range, cell As Range ...
    (microsoft.public.excel.programming)
  • Project 2007 Issues
    ... I noticed when I added the group-by, ... I changed the background color of a row to Aqua, ... background color of all cells except for this "Task Name" cell while in Gant ... colored Aqua including this "Task Name" cell. ...
    (microsoft.public.project)