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.
- How to Use Lists
- Customize Your JList Display
- Basic Swing components II
- JLists, Data Models, and Cell Renderers
Solution 3
You create a JList
with a ListModel
. When you edit your ListModel
, it is reflected on JList
as well.
Author by
TopChef
Updated on July 09, 2022Comments
-
TopChef almost 2 years
Does anyone have any good tutorials on how to fill a
JList
(within aJPanel
) with user inputted data. Specifically, I want to add people to a selected roster. Is this a matter of filling it with anArrayList
?Any help would be much appreciated.
-
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 over 12 yearsWell, somebody else was first, but that response seems to be removed... ;-)