Article View: borland.public.jbuilder.java.swing
Article #12659Re: How to delete a row in a JTable
From: Vladimir Olenin
Date: Wed, 18 Nov 1998 00:00
Date: Wed, 18 Nov 1998 00:00
122 lines
4104 bytes
4104 bytes
This is a multi-part message in MIME format.
--------------C5326CEBDC5894298E079E4D
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit
Well, actually have no a faint idea about the cause of your problem. But
u can try this function:
table.tableChanged(new TableModelEvent( PARAMETERS ));
though as far as i know it does practically the same fireXxx funcs do.
But anyway it might help. The other solution that would help almost 4
sure is setting model after each changing of the table
(setModel(MyTableModel)).
Hope this helped a bit.
Vladimir
Phillipus wrote:
>
> Does anyone know how to properly delete a row in a JTable?
>
> I have a JTable whose model is an implementation of AbstractTableModel.
> The objects that are to be displayed in the table are stored in a Vector
> so that we have something like this:
>
> public class MyTableModel extends AbstractTableModel implements
> Cloneable, Serializable {
> private Vector myObjectList;
> private JTable table; // the table whose model this is
>
> public MessageTableModel(JTable table) {
> super();
> this.table = table;
> myObjectList = new Vector();
> }
>
> public void addObject(Object myObject) {
> myObjectList.addElement(myObject);
> fireTableRowsInserted(getRowCount(), getRowCount());
> }
>
> public void removeObject(Object myObject) {
> myObjectList.removeElement(myObject);
>
> // NOW WHAT?????????
> }
>
> public Object getValueAt(int rowIndex, int columnIndex) {
> Object myObject = (Object)myObjectList.elementAt(rowIndex);
> return myObject;
> }
>
> public int getColumnCount() {
> return 2;
> }
>
> public int getRowCount() {
> return myObjectList.size();
> }
>
> public String getColumnName(int columnIndex) {
> String retVal = "";
> switch(columnIndex) {
> case 0:
> retVal = "Subject";
> break;
> case 1:
> retVal = "Date";
> break;
> }
> return retVal;
> }
>
> }
>
> addObject works and the table is updated. But when I remove an object
> from the Vector the program calls getValueAt and obviously the data is
> now invalid. I have tried the following:
>
> fireTableRowsDeleted
> fireTableChanged
> fireTableDataChanged
>
> and so on....
>
> all to no avail.
>
> So what is the correct way of notifying table and/or model that an
> element has been removed frm the data Vector?
>
> Answers greatly appreciated...
>
> Phillipus
--
>~~~~~~~~<=============>~~~~~~~~<
Be yourself no matter what they say...
Join in Java community now!
http://www.geocities.com/SiliconValley/Heights/9815
>~~~~~~~~<=============>~~~~~~~~<
--------------C5326CEBDC5894298E079E4D
Content-Type: text/x-vcard; charset=koi8-r;
name="keenonjava.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Vladimir Olenin
Content-Disposition: attachment;
filename="keenonjava.vcf"
begin:vcard
n:Vladimir;Olenin
x-mozilla-html:FALSE
adr:version:2.1;;;;;;
version:2.1
email;internet:keenonjava@collegemail.com
note:Java programmer. Open for project development offers. See my home page at: http://www.geocities.com/SiliconValley/Heights/9815/
end:vcard
--------------C5326CEBDC5894298E079E4D--
Technical Details
Message-ID:
<3651FF68.A402B586@collegemail.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36518E57.949D9FA0@bangor.ac.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e8d4105e0b153509 X-Google-Attributes: gid111d45,public From: Vladimir Olenin <keenonjava@collegemail.com> Subject: Re: How to delete a row in a JTable Date: 1998/11/18 Message-ID: <3651FF68.A402B586@collegemail.com> X-Deja-AN: 412934975 References: <36518E57.949D9FA0@bangor.ac.uk> X-Accept-Language: en,ru Content-Type: multipart/mixed; boundary="------------C5326CEBDC5894298E079E4D" Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing