🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #11107

Re: Rendering colors in specific JTable cells

#11107
From: Tad Frysinger
Date: Wed, 07 Jul 1999 00:00
35 lines
1651 bytes
In article <37839DDA.12B7E3B7@cs.virginia.edu>, lcohen@cs.virginia.edu 
says...
> JTable calls on my table model to deliver specific cells by specifying a
> (row,col) pair. Based on the current state of the particular (row,col)
> object, I want to color the text value that JTable displays in the cell.
> 
> How is this done?
> 
> Thanks, Leo Cohen
> 
> 
You install a component that implements the TableCellRenderer interface.  
It will get called to return the component that displays the contents of 
that cell.  Check out DefaultTableCellRenderer for ideas.  You then must 
tell the JTable to use it, by installing as the default renderer (there 
is one renderer per data type class in this mode), by column, or you can 
create an anonymous subclass of JTable and override the getCellRenderer 
method:

table = new JTable(...) 
{
  public TableCellRenderer getCellRenderer(int row, int column) 
  {
     if ((row == 0) && (column == 0)) 
     {
       return myCustomRenderer;
     }
     return super.getCellRenderer(row, column);
  }
};

If you do it by column, you must install the renderer in the TableColumn 
object itself.

Tad Frysinger (TeamB)
Technical Details
Message-ID: <MPG.11ed842bf6db1e5989a44@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37839DDA.12B7E3B7@cs.virginia.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,7eca3b4a9a78a9f4
X-Google-Attributes: gid111d45,public
From: tfrysinger@earthlink.net (Tad Frysinger)
Subject: Re: Rendering colors in specific JTable cells
Date: 1999/07/07
Message-ID: <MPG.11ed842bf6db1e5989a44@forums.borland.com>
X-Deja-AN: 498322663
References: <37839DDA.12B7E3B7@cs.virginia.edu>
Organization: Freezone Enterprises
Newsgroups: borland.public.jbuilder.java.swing