Filling a JList with data

22,540

Solution 1

  • create a ListModel which wrapps your java.util.List (e.g. by extending AbstractListModel)
  • configure JList to use this model
  • create and configure a renderer to format/ display the Objects in your list as needed

http://docs.oracle.com/javase/tutorial/uiswing/components/list.html

Solution 2

I think it is having a little bit time with Google. I find the following results with Google.

Solution 3

You create a JList with a ListModel. When you edit your ListModel, it is reflected on JList as well.

Share:
22,540
TopChef
Author by

TopChef

Updated on July 09, 2022

Comments

  • TopChef
    TopChef almost 2 years

    Does anyone have any good tutorials on how to fill a JList (within a JPanel) with user inputted data. Specifically, I want to add people to a selected roster. Is this a matter of filling it with an ArrayList?

    Any help would be much appreciated.

  • camickr
    camickr over 12 years
    +1, for being the first to link to the Swing tutorial which has a working example that does exactly what the OP wants to do.
  • Puce
    Puce over 12 years
    Well, somebody else was first, but that response seems to be removed... ;-)