🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #8020

Re: JList only showing one selection

#8020
From: Joi Ellis [TeamB]
Date: Wed, 08 Nov 2000 01:26
58 lines
3553 bytes
Kevin Dwan <kevin@blueberry.com> wrote:


> Yes, I've read the Tutorial. It says, "To create a list whose items can be
> changed individually, set the list's model to an instance of a mutable list
> model class, such as an insteance of DefaultListModel. You can set a list's
> model when you create the list or by calling the setModel method."

> This is what I tried:

> JFileChooser sfc = new JFileChooser();
> .
> .
> void approveButton_actionPerformed(ActionEvent e)
>   {
>     DefaultListModel hank = new DefaultListModel();
>     JList1.setModel(hank);
>     JList1.clearSelection(); //doesn�t clear JList1
>     hank.clear();  //doesn�t clear JList1
>     hank.removeAllElements();//doesn�t clear JList1
>     File [] sourceFiles = sfc.getSelectedFiles();
>     String[] namelist = new String [sourceFiles.length];
>       for (int i = 0; i < sourceFiles.length; i++){
>         namelist[i] = sourceFiles[i].getName();
>           for (int a = 0; a < namelist.length; a++){
>             hank.addElement(namelist[a]);
>           }
>       }
>         JList JList1 = new JList(hank);
>         //JList JList1 = new JList(namelist); //used this approach earlier
>         targetPanel.add(JList1, new XYConstraints(14, 17, 210, 279));
>           for (int a=0; a<JList1.getModel().getSize();a++){
>             System.out.println(JList1.getModel().getElementAt(a)); //diagnostic
>           }
>   }

> What this does is update the JList, as I can see by the System.out.println
> diagnostic, but JList1 in the GUI doesn't get updated at runtime.

Okay, I'm confused.  In the actionPerformed method you're creating a new,
empty list model and assigning that to an existing JList?

JList1.clearSelection() doesn't erase the list contents, it clears any 
selections the user may have made by clicking on list items.

Then you hank.clear() or hank.removeAllElements(), then build it again, then
create net another JList...?  None of the secondary JLists are visible
anywhere, they just exist somewhere in your namespace. The Jlist that's
being displayed is now orphaned and isn't getting updated anywhere.

You should create one JList, add it to your frame, and then never create
another one while that frame is visible.  Only manipulate the data in the
model you used for creating the JList.

-- 
Joi Ellis (TeamB) 
No direct email, please.
For best results, post on news server newsgroups.borland.com!
Technical Details
Message-ID: <8uaa4e$l9u8@bornews.inprise.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!skynet.be!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail
References: <3A021239.92AF1FD4@blueberry.com> <8tt9hf$kml3@bornews.borland.com> <3A0363E0.2BF1797E@blueberry.com> <8tvor2$dfj4@bornews.borland.com> <3A075600.642F986E@blueberry.com> <8u88oh$2q10@bornews.inprise.com> <3A089F21.40D91144@blueberry.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,34638f00403429f8
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2000-11-07 17:30:45 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!skynet.be!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: JList only showing one selection
Date: 8 Nov 2000 01:26:38 GMT
Organization: Another Netscape Collabra Server User
Lines: 58
Message-ID: <8uaa4e$l9u8@bornews.inprise.com>
References: <3A021239.92AF1FD4@blueberry.com> <8tt9hf$kml3@bornews.borland.com> <3A0363E0.2BF1797E@blueberry.com> <8tvor2$dfj4@bornews.borland.com> <3A075600.642F986E@blueberry.com> <8u88oh$2q10@bornews.inprise.com> <3A089F21.40D91144@blueberry.com>
NNTP-Posting-Host: linux.aravox.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.14-5.0 (i686))