Article View: borland.public.jbuilder.java.swing
Article #7819Re: JTable Questions
From: John McGrath TeamB
Date: Tue, 02 Jan 2001 05:25
Date: Tue, 02 Jan 2001 05:25
50 lines
3236 bytes
3236 bytes
On Fri, 29 Dec 2000 22:51:29 -0000, Niall Pemberton wrote:
> your table cell renderer is strange...I'm not an expert but I
> don't think you need a setValue() method in it ... you need to
> implement a getTableCellRendererComponent() method as below,
James's renderer is derived from DefaultTableCellRenderer, which
provides the getTableCellRendererComponent() method, and uses the
setValue() method to get the cell value. It also sets the foreground
and background colors and draws selection borders.
But I much prefer your code, since a renderer is pretty easy to write
from scratch, and DefaultTableCellRenderer does not really help much,
especially if you want to change the foreground and background colors.
I have also found that it gets in the way at times.
But you might want to look at the code for DefaultTableCellRenderer to
see how it implements the getTableCellRendererComponent() method.
There are some optimizations that it does that can make a difference in
rendering performance.
> On the subject of initialising the values, you don't have to
> do it. Set up your own Table Model as below, using a HashMap
> to only store values when you actually have one:
I agree that it is better to not store the PcCharacter values for
"empty" cells (see my other message). But for efficiency, I would use
a two dimensional array to store the values rather than a HashMap.
The HashMap might make a lot of sense if the size of the table was
unbounded, or it was *very* sparse. But I don't think the added
overhead of a HashMap makes sense in this case, since the table size is
fixed and probably not that sparse.
The HashMap implementation also has some allocations that would occur
during rendering, while the array implementation has no additional
allocations. Please note that I think it is seldom a good idea to
sacrifice the clarity of the code or design in the name of efficiency,
but the array implementation is at least as clear as a HashMap, and I
think that rendering code is one place where a little extra attention
to performance makes sense.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.14bb20b312ac63ae989e13@forums.borland.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!xfer13.netnews.com!netnews.com!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!not-for-mailReferences:
<92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.com> <92nedq$66a1@bornews.inprise.com> <3a4fb895_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,7fa15b59fdc30449 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2001-01-01 21:30:25 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!xfer13.netnews.com!netnews.com!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!not-for-mail From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.swing Subject: Re: JTable Questions Date: Tue, 2 Jan 2001 00:25:01 -0500 Organization: Another Netscape Collabra Server User Lines: 50 Message-ID: <MPG.14bb20b312ac63ae989e13@forums.borland.com> References: <92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.com> <92nedq$66a1@bornews.inprise.com> <3a4fb895_1@dnews> NNTP-Posting-Host: dslcv1-60.fast.net X-Newsreader: MicroPlanet Gravity v2.30