Article View: borland.public.jbuilder.java.language
Article #384Re: Editing elements in an ArrayList
From: Alexey N. Solofnenko
Date: Wed, 18 May 2005 20:20
Date: Wed, 18 May 2005 20:20
47 lines
2741 bytes
2741 bytes
Java works with whatever was returned by your table model. If you do not
want for the value to be copied, do not copy it.
- Alexey.
Richard M. Ulrich wrote:
> 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
>
>
--
Alexey N. Solofnenko {trelony at gmail.com}
home: http://trelony.cjb.net/
Technical Details
Message-ID:
<428ba393$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<428ba23d@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,66edc0329a6a0d42 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 18 May 2005 13:20:37 -0700 From: "Alexey N. Solofnenko" <trelony@mail.ru> User-Agent: Mozilla Thunderbird 1.0+ (Windows/20050515) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Editing elements in an ArrayList References: <428ba23d@newsgroups.borland.com> In-Reply-To: <428ba23d@newsgroups.borland.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 208.200.221.5 Message-ID: <428ba393$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1116447635 208.200.221.5 (18 May 2005 13:20:35 -0700) Lines: 47 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail