Article View: borland.public.jbuilder.java.swing
Article #9993Re: JTable and TableModelListener
From: Remon Huijts
Date: Wed, 08 Dec 1999 00:00
Date: Wed, 08 Dec 1999 00:00
33 lines
1802 bytes
1802 bytes
>I'm having trouble setting up an event listener for my JTable.
...
>For some reason, tableChanged never gets called when the table values are
>edited.
When you create you're own TableModel, as you did in the following block...
tableModel = new AbstractTableModel()
{
public int getColumnCount() { return 4; }
...
};
... you should make sure that somewhere a TableModelEvent is thrown,
otherwise your Frame1 will never catch it, and the method tableChanged will
never be invoked. AbstractTabelModel provides usefull convenience methods
for throwing a TableModelEvent, and because you extended that class, you can
do the following:
tableModel = new AbstractTableModel()
{
public int getColumnCount() { return 4; }
...
public void setValueAt(Object value, int row, int column) {
...; // Put your code here if you already overwrote this method.
fireTableCellUpdated(row, column);
}
};
Every time the table values are edited, the method setValueAt is invoked, so
now that a TableModelEvent is created and thrown in that method, listeners
will wake up...
Technical Details
Message-ID:
<82kgom$639$1@news.worldonline.nl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<FRp04.12884$MZ.88984@ozemail.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,233d1bc75a860621 X-Google-Attributes: gid111d45,public From: "Remon Huijts" <pirore@tip.nl> Subject: Re: JTable and TableModelListener Date: 1999/12/08 Message-ID: <82kgom$639$1@news.worldonline.nl> X-Deja-AN: 558265403 References: <FRp04.12884$MZ.88984@ozemail.com.au> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: newsmaster@worldonline.nl X-Trace: news.worldonline.nl 944621142 6249 195.241.234.120 (8 Dec 1999 02:45:42 GMT) Organization: WorldOnline News server NNTP-Posting-Date: 8 Dec 1999 02:45:42 GMT Newsgroups: borland.public.jbuilder.java.swing