🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

How to refill a JList?

#12639
From: Andre Koster
Date: Fri, 04 Dec 1998 00:00
57 lines
2221 bytes
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();
    }
}
Technical Details
Message-ID: <36680506.B461C441@luna.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

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