🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to refill a JList?

#12566
From: Andre Koster
Date: Tue, 08 Dec 1998 00:00
71 lines
2716 bytes
The solution is that a JList has a function called 'setListData'.
With this, new data can be placed in the list. 

I found this info at 
http://java.sun.com/docs/books/tutorial/ui/swingComponents/list.html

Andre Koster


Andre Koster wrote:
> 
> Hi,
> 
> I want to refill a previously filled JList. I have my JList displayed
> on a JScrollPane, and the JList contains an array of Strings.
> 
> I tried to simply create a new JList with the new data, but that
> didn't do anything. Neither did assigning an array with new data
> to the array with old data. The only thing that worked was to
> individually assign a new String to each array entry. I can't imagine
> this is the proper way to do this. Besides, I want to be able to
> have a new list with a different size than the old list. If I can
> only replace individual Strings, the size of the array stays the same.
> 
> My code looks basically like this. The routine 'fillList' may be called
> more than once. Like it is now, it fills the list once properly.
> Refilling the list doesn't work.
> 
> public class MyFrame extends JFrame
> {
>     JScrollPane     jScrollPane = new JScrollPane();
>     JList           jList; // Creation of the list is postponed until
>                            // the data for it is available.
>     public MyFrame()
>     {
>         try
>         {
>             jbInit();
>             show();
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         }
>     }
> 
>     private void jbInit() throws Exception
>     {
>         ...
>         this.getContentPane().add(jScrollPane,
>                 new XYConstraints(7, 117, 315, 115));
>         jScrollPane.getViewport().add(jList, null);
>         ...
>     }
> 
>     private void fillList(int iNrOfLines)
>     {
>         astringListLines = new String[iNrOfLines];
> 
>         [...astringListLines is filled with values...]
> 
>         // Connect the array of strings to jList.
> 
>         jList = new JList(astringListLines);
>         repaint();
>     }
> }

-- 

                Andre S.E. Koster   ---    Andre.Koster@luna.nl
Technical Details
Message-ID: <366D4DBF.DDB06E33@luna.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36680506.B461C441@luna.nl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,996cff2664472bcc
X-Google-Attributes: gid111d45,public
From: Andre Koster <Andre.Koster@luna.nl>
Subject: Re: How to refill a JList?
Date: 1998/12/08
Message-ID: <366D4DBF.DDB06E33@luna.nl>
X-Deja-AN: 420085962
Content-Transfer-Encoding: 7bit
References: <36680506.B461C441@luna.nl>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing