Java Swing Updating JList

南笙酒味 提交于 2019-12-20 04:15:55

问题


I'd like to know if there is any way that I can update a Jlist after the user adds or removes an item to it and after a user sorts it. Is there any way that I can write a standardized method to update the display based on the order of items in an array or vector, and when the user remove or adds an object from the array that the JList is based on?

Thank you.


回答1:


Updates should be made to the ListModel, not the Array that was used to create the model.

However, if you want to refresh the list with completely new items or change the order of the items then you create a new DefaultListModel and use the setModel(...) method of the JList to update the view.



来源:https://stackoverflow.com/questions/1851217/java-swing-updating-jlist

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