问题
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.
回答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
回答2:
You create a JList
with a ListModel
. When you edit your ListModel
, it is reflected on JList
as well.
回答3:
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
回答4:
Use any layout manager like Gridlayout.
来源:https://stackoverflow.com/questions/8402205/filling-a-jlist-with-data