Filling a JList with data

TopChef picture TopChef · Dec 6, 2011 · Viewed 21.8k times · Source

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.

Answer

Puce picture Puce · Dec 6, 2011
  • 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