🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

JTable Questions

#7799
From: James A. Schulz
Date: Sat, 30 Dec 2000 19:10
38 lines
2648 bytes
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: <92lbpr$6ro1@bornews.inprise.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!portc01.blue.aol.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,7fa15b59fdc30449,start
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2000-12-30 11:08:39 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!portc01.blue.aol.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail
From: "James A. Schulz" <jaschulz@wiseware.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: JTable Questions
Date: Sat, 30 Dec 2000 13:10:38 -0600
Organization: Another Netscape Collabra Server User
Lines: 40
Message-ID: <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