Filling a JList with data
Asked Answered
T

4

5

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.

Timothytimour answered 6/12, 2011 at 15:17 Comment(2)
It should generally be JList -> JScrollPane -> JPanel.Overweight
@Timothytimour question about ..with user inputted data, are you look for editable JList contents ???Rotary
T
7
  • 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

Tropopause answered 6/12, 2011 at 15:28 Comment(2)
+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.Mixon
Well, somebody else was first, but that response seems to be removed... ;-)Tropopause
Z
2

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

Zoroastrianism answered 6/12, 2011 at 15:21 Comment(0)
D
2

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

Dollop answered 6/12, 2011 at 15:36 Comment(0)
M
-1

Use any layout manager like Gridlayout.

Maynardmayne answered 6/12, 2011 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.