Article View: borland.public.jbuilder.java.swing
Article #9548Re: jTable how do I remove a row??
From: Steve Horsley
Date: Tue, 14 Mar 2000 00:00
Date: Tue, 14 Mar 2000 00:00
44 lines
2187 bytes
2187 bytes
I think the way to go is for your tableModel to extend the
AbstractTableModel class. I did similar, and only had to override
these methods:
getRowCount()
getColumnCount()
getValueAt(int row, int column)
getColumnName(int col)
Then when the underlying data changed, I just called one of the
fire....() methods to tell it what had changed. The really lazy one
is fireTableDataChanged() but if you are more specific, the table
repainting might be slicker.
In my case, the data was all in a Vector, and each entry in the Vector
contained all the data needed for a row, but the data could really be
in any form you want.
The thread that changed the data first modified the data, then called
myTableModel.fire...(). e.g.
myVector.add(thingy);
myTableModel.fireTableDataChanged();
Both these were performed in a SwingUtilities.invokeLater(Runnable)
call,
so that table contents and the visible swing stuff were only ever
modified by the event thread. This trick sidestepped multi-threading
sync problems.
The fire...() calls seem to end up sending a TableModelEvent to the
JTable which is registered as a listener, but all the messy work is
done for you by the AbstractTableModel. Neat!
Hope this helps,
Steve.
//-----------------------------
Site View Technologies wrote:
>
> First adventure into swing JTables. I would simply like to
> know how to delete an entire row, I have looked high and low
> but have not found a solution.
>
>
> Should I override the default model, is there a simply trick
> to this, or should I select another type of view format.
Technical Details
Message-ID:
<38CE0672.FE426EF1@cwcom.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38CCF49C.ED4DF7ED@siteviewtech.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f6e9713f1cd0f5b6 X-Google-Attributes: gid111d45,public From: Steve Horsley <steve.horsley@cwcom.co.uk> Subject: Re: jTable how do I remove a row?? Date: 2000/03/14 Message-ID: <38CE0672.FE426EF1@cwcom.co.uk> X-Deja-AN: 597272235 Content-Transfer-Encoding: 7bit References: <38CCF49C.ED4DF7ED@siteviewtech.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Trace: 14 Mar 2000 01:21:01 -0800, 194.200.13.1 MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing