🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: can i have several different formats for the Double class in a JTable?

#8082
From: John McGrath TeamB
Date: Sat, 21 Oct 2000 00:00
40 lines
2093 bytes
On Fri, 20 Oct 2000 20:57:09 -0400, Zachary Cooper wrote:

> I have a custom cell renderer and cell editor for a JTable
> that displays columns of Double classes with 5 decimal
> places.  I now want to have 3 different formats for Double
> types in the table, one showing 2 places, one showing 3
> places, and one showing 5 places.  Since the
> JTable.setDefaultRenderer() method set a renderer for
> each class type, what's the best way to so this?

Are the number of decimal places the same for all of the cells in a 
single table column?  If so, you can set the renderer based on the table 
column.  For example:

    table.getColumn(id).setCellRenderer(renderer);
or
    table.getColumnModel().getColumn(i).setCellRenderer(renderer);

If not, and the number of decimals can be determined based on which cell 
is being rendered, you can override the getCellRenderer(row,column) 
method of JTable to return the appropriate renderer for any given cell.

If the number of decimals depends on the cell value, you can modify your 
cell renderer to configure the renderer component as needed in the 
getTableCellRendererComponent() method.  This approach could also be used 
to configure the renderer component based on the row and column.


> Will extending the Double class to 3 'dummy' extensions
> and then implementing a renderer for each work?

No.  The Double class is final.

-- 
Regards,
John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.145afc35fb2ae2be989c65@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <39f0e774$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,8fe3c7e5c7b153f6
X-Google-Attributes: gid111d45,public
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Subject: Re: can i have several different formats for the Double class in a JTable?
Date: 2000/10/21
Message-ID: <MPG.145afc35fb2ae2be989c65@forums.borland.com>
X-Deja-AN: 684060254
References: <39f0e774$1_1@dnews>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing