Article View: borland.public.jbuilder.java.swing
Article #7801Re: JTable Questions
From: James A. Schulz
Date: Sat, 30 Dec 2000 23:02
Date: Sat, 30 Dec 2000 23:02
55 lines
3014 bytes
3014 bytes
Please ignore these questions.
James
"James A. Schulz" <jaschulz@wiseware.com> wrote in message
news:92lbpr$6ro1@bornews.inprise.com...
> I need to display a grid (55x25) of characters, and I need to control the
> colors (foreground and background) of each cell.
>
> Question 1: Should I use a table of Strings for this purpose? Or would a
> table of Characters be better? If the latter is preferable, how do I
> initialize my table with empty cells? Or, since I need to control and
> maintain the colors of each cell, would a table of Object (where the
object
> would contain one char, and two ints for the colors) be the best choice?
> Again, how would I initialize such a table?
>
> Question 2: I know how to replace the DefaultCellRenderer, and I have seen
> several examples which show how to change cell colors based on cell value,
> but I need to control cell colors based solely on position in the grid and
I
> do not see how, in the custom renderer's code, I can check the row and
> column of the cell being rendered. For instance, in my current effrot I
am
> using a table of strings and I am using the following renderer to center
the
> string (containing just one character):
>
> public class MyCellRenderer extends DefaultTableCellRenderer {
> public MyCellRenderer(int align) {
> this.align = align;
> };
> protected void setValue(Object value) {
> super.setValue(value);
> setHorizontalAlignment(align);
> };
> protected int align;
> };
>
> I know that I can use setForeground and setBackground in the context of
the
> setValue method, but I don't see how, in the method, I can test for cell
row
> and column values. If I were using a table of custom objects (as
mentioned
> above) then the row and column values would come in the "value" argument
of
> the function, so maybe that is a reason to prefer a table of custon
Objects.
>
> thanks to anyone who can help.
>
> James
>
>
Technical Details
Message-ID:
<92lpc1$6bj10@bornews.inprise.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.mesh.ad.jp!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!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>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: 2000-12-30 15:02:33 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.mesh.ad.jp!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!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: "James A. Schulz" <jaschulz@wiseware.com> Newsgroups: borland.public.jbuilder.java.swing Subject: Re: JTable Questions Date: Sat, 30 Dec 2000 17:02:12 -0600 Organization: Another Netscape Collabra Server User Lines: 57 Message-ID: <92lpc1$6bj10@bornews.inprise.com> References: <92lbpr$6ro1@bornews.inprise.com> Reply-To: "James A. Schulz" <jaschulz@wiseware.com> NNTP-Posting-Host: 165.121.198.13 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200