🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JTable Questions

#7806
From: James A. Schulz
Date: Sun, 31 Dec 2000 14:07
63 lines
3072 bytes
John,

Thanks for your extensive and very instructive answer to my JTable
questions.

I think I have found a solution for most of my problems.  My table stores
objects which comprise a character, and two colors, and my cell renderer
works like this:

  public class PcCellRenderer extends DefaultTableCellRenderer {
    public PcCellRenderer(int align) {
      this.align = align;
    };
    protected void setValue(Object value) {
      PcCharacter c = (PcCharacter)value;
      super.setValue(value);
      setForeground(c.getForeground());
      setBackground(c.getBackground());
      setHorizontalAlignment(align);
    };
    protected int align;
  };

And this works fine.

However, I still have two problems.  My table is fairly big, 55x25).  I want
to initialize all the cells to hold the same (blank) character, but I
certainly don't want to write out those vectors.  I tried using a for loop
in the context to a custom tablemodel declaration, like this:

  TableModel tm = new AbstractTableModel() {
    PcCharacter[][] data =
{{blankPcCharacter,blankPcCharacter,blankPcCharacter},

{blankPcCharacter,blankPcCharacter,blankPcCharacter}};
    String[] headers = {"","",""};
    public int getRowCount() { return data.length; };
    public int getColumnCount() { return headers.length; };
    public Object getValueAt(int r, int c) { return data[r][c]; };
    public void setValueAt(Object value, int r, int c) {
      data[r][c] = (PcCharacter)value;
      repaint();
    };
    public String getColumnName(int c) { return ""; };
    int i,ii;
    for (i = 0;i < 2;i++){
      for(ii=0;ii<3;ii++){
        data[i][ii] = blankPcCharacter
      }
    }
  };

but the compiler doesn't like thiis.  How do I use for loops to initialize
my table:

Also, you will note a call to repaint() in my tablemodel declaration
(above).  With out this setValueAt does not paint the cell, my question is
about whether this call to repaint() is the best, most efficient way to
handle this.

thanks again for all your help,

James
Technical Details
Message-ID: <92nedq$66a1@bornews.inprise.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!newsfeed.icl.net!ldn-newsfeed.speedport.net!newsfeed.speedport.net!naxos.belnet.be!news.belnet.be!bornews.borland.com!not-for-mail
References: <92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.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-31 06:09:30 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!newsfeed.icl.net!ldn-newsfeed.speedport.net!newsfeed.speedport.net!naxos.belnet.be!news.belnet.be!bornews.borland.com!not-for-mail
From: "James A. Schulz" <jaschulz@wiseware.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: JTable Questions
Date: Sun, 31 Dec 2000 08:07:40 -0600
Organization: Another Netscape Collabra Server User
Lines: 65
Message-ID: <92nedq$66a1@bornews.inprise.com>
References: <92lbpr$6ro1@bornews.inprise.com> <MPG.14b89345ccc5b0c7989e08@forums.borland.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