Article View: borland.public.jbuilder.java.swing
Article #8860Re: JTable
From: John P. McGrath
Date: Thu, 06 Jul 2000 00:00
Date: Thu, 06 Jul 2000 00:00
38 lines
1773 bytes
1773 bytes
On Wed, 05 Jul 2000 15:52:32 +0200, sven goetgeluck wrote:
> must create at runtime a table with diffents count of rows,
> is this possible?
> all examples found have fixed rowlength , how can i insert
> a row ..
> I use a jtable with a model
:
> final Object[][] data = null;
Since you provide the TableModel, you need to manage the data structures
that hold the data. A Java array of arrays is not the best structure to
use for this. Instead, try using an ArrayList of ArrayLists, or a Vector
of Vectors if you are stuck on JDK 1.1, or if your table model needs to
be synchronized.
> public void addRow(Object[] rowdata)
> {
> fireTableCellUpdated(row, col);
>
> }
After adding the row (not before), you will need to fire an event to
notify listeners that the row has been added. But fireTableCellUpdated()
notifies listeners that the value of one cell has changed. When you add
a row you should use:
fireTableRowsInserted( int firstRow, int lastRow )
Take a closer look at AbstractTableModel. There are 7 different fireXXXX
methods there for notifying listeners about different changes. If you
use the wrong one, your code may not behave properly or it may run a lot
slower than need be.
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.13cde3eed0933ce4989a13@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39633DA0.A4D28790@officeline.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,a00bcc41b12b3cb4 X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: JTable Date: 2000/07/06 Message-ID: <MPG.13cde3eed0933ce4989a13@forums.borland.com> X-Deja-AN: 642940645 References: <39633DA0.A4D28790@officeline.be> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing