🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JTable problem

#9789
From: John P. McGrath
Date: Fri, 28 Jan 2000 00:00
45 lines
2437 bytes
On Wed, 26 Jan 2000 17:49:16 +0100, Jurgen Berden wrote:

> I'm working with a splitpane, one part contains a JTable,
> the other part has a textbox and a pushbutton.  I would
> like to manipulate the Table now. In other words the Table
> needs to be changed depending on the textbox' input (and
> on the actionlistener from the pushbutton)
> 
> The entire table, data, amount of rows and columns depend
> thus, on the input from the user. It's not a problem to get
> all the information from the table, but for some reason I
> can't update the "JTable"-part of the splitpane and actually
> see it on screen. I can't seem to find a method which updates
> my table.

I am guessing that you created your JTable using the the constructor:

    JTable( Vector rowData, Vector columnNames );
          
If so, then setting the values in the Vector will not work, since the 
JTable has no way of knowing that the value has changed.

A JTable gets the values to display in the table using a TableModel, and 
it listens for TableModelEvents from the TableModel, so it knows when a 
table value, the number of rows or the number of columns is changed.

When you use the above constructor, JTable creates a TableModel for you 
that gets the values from the Vector.  If you did not need to change the 
number of rows and columns, you could use the following TableModel method 
to set the values, and it would notify the JTable of the change.

    void setValueAt( Object aValue, int rowIndex, int columnIndex );

In order to be able to change the number of rows and columns in the 
table, you will have to create a TableModel and construct your JTable 
from that TableModel.

There is an implementation of the TableModel interface that may satisfy 
your needs:  DefaultTableModel.  If this does not work, you can create 
your own TableModel class, probably derived from AbstractTableModel.

-- 
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.12fb2d3e19afcd8598974e@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <388F258C.D02558C1@esat.kuleuven.ac.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,b81e2823b25cc2ed
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: JTable problem
Date: 2000/01/28
Message-ID: <MPG.12fb2d3e19afcd8598974e@forums.borland.com>
X-Deja-AN: 578684837
References: <388F258C.D02558C1@esat.kuleuven.ac.be>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing