Filling a JList with data

﹥>﹥吖頭↗ 提交于 2021-01-27 10:21:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!