Article View: borland.public.jbuilder.java.swing
Article #8128Re: JList only showing one selection
From: Kevin Dwan
Date: Fri, 03 Nov 2000 00:00
Date: Fri, 03 Nov 2000 00:00
47 lines
2269 bytes
2269 bytes
"Joi Ellis [TeamB]" wrote:
> Kevin Dwan <kevin@blueberry.com> wrote:
> > void approveButton_actionPerformed(ActionEvent e)
> > {
> > JList1.clearSelection();
> > File [] sourceFiles = new File[]{};
> > sourceFiles = sfc.getSelectedFiles();
> > for (int i = 0; i < sourceFiles.length; i++){
> > String[] namelist = {sourceFiles[i].getName()};
> > JList JList1 = new JList(namelist);
>
> What are you attempting to do here? You're creating a new
> String[] namelist each pass through the loop, and each one contains a single
> file. Then you create a new JList from that namelist of size 1. This
> doesn't make any sense to me.
>
> If I wanted to suck names out of the chooser, I'd start with something like:
>
> File[] sourceFiles = getSelectedFiles();
> String[] namelist = new String[ sourceFiles.length ];
> for (int i = 0; i < sourceFiles.length; i++) {
> namelist[i] = sourceFiles[i].getName();
> }
> JList jlist1 = new JList( namelist );
>
> > targetPanel.add(JList1, new XYConstraints(14, 17, 210, 279));
> > for (int a=0; a<JList1.getModel().getSize();a++){
> > //displays what's actually in the JList
> > System.out.println(JList1.getModel().getElementAt(a));
> > }
> > }
> > }
>
> --
> Joi Ellis (TeamB)
> No direct email, please.
> For best results, post on news server newsgroups.borland.com!
Thanks, Joi. That did it.
Do you have a suggestion for clearing the JList, so that if the user changes the
selection, the old values get zapped?
I thought JList1.clearSelection would do it, but it does not.
Technical Details
Message-ID:
<3A0363E0.2BF1797E@blueberry.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3A021239.92AF1FD4@blueberry.com> <8tt9hf$kml3@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,34638f00403429f8,start X-Google-Attributes: gid111d45,public From: Kevin Dwan <kevin@blueberry.com> Subject: Re: JList only showing one selection Date: 2000/11/03 Message-ID: <3A0363E0.2BF1797E@blueberry.com> X-Deja-AN: 689445078 Content-Transfer-Encoding: 7bit References: <3A021239.92AF1FD4@blueberry.com> <8tt9hf$kml3@bornews.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing