Article View: borland.public.jbuilder.java.language
Article #383Editing elements in an ArrayList
From: Richard M. Ulrich
Date: Wed, 18 May 2005 20:15
Date: Wed, 18 May 2005 20:15
35 lines
2402 bytes
2402 bytes
Hello,
I have a JTable whose TableModel stores data in an ArrayList of ArrayLists.
Perhaps because I am more used to C++ (where I know exactly where my data
resides), I am having trouble editing cell entries.
Stripped to its essentials, the code to edit an entry is as follows, where
ds is an instance of an implemented AbstractTableModel
Element elem = (Element) ds.getObjectAt(gridrow, gridcol);
eresults.copy(elem.results);
//puts new results into elem.results
ds.setValueAt((Object) elem,gridrow,gridcol);
Again stripping out all of the code to handle error checking and such,
getObjectAt is equivalent to two lines:
ArrayList aRow = (ArrayList) table.get(gridrow);
return ( aRow.get(columnIndex) );
and setValueAt to two lines
ArrayList aRow = (ArrayList) table.get(gridrow);
aRow.set(gridcol, elem);
Now for the dumb questions. When I have ds.getObjectAt(gridrow, gridcol),
am I getting a new copy of the data, or a reference to the existing data?
When I have ds.setValueAt((Object) elem,gridrow,gridcol), is Java creating a
new copy of elem, or is the ArrayList now pointing to the local object? If
it is the second case, then it would seem like I don't really need to call
setValueAt, except for the side-effect of calling fireTableCellUpdated().
Thanks,
Richard
Technical Details
Message-ID:
<428ba23d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,66edc0329a6a0d42,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Richard M. Ulrich" <RichardU@UlrichAssociates.com> Newsgroups: borland.public.jbuilder.java.language Subject: Editing elements in an ArrayList Date: Wed, 18 May 2005 16:15:29 -0400 Lines: 37 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 NNTP-Posting-Host: 12.101.9.226 Message-ID: <428ba23d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1116447293 12.101.9.226 (18 May 2005 13:14:53 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail