简体   繁体   English

Java Swing更新JList

[英]Java Swing Updating JList

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. 我想知道在用户添加或删除项目之后以及用户对其进行排序之后是否有任何方法可以更新Jlist。 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? 有没有什么办法可以编写一个标准化的方法来根据数组或向量中的项目顺序更新显示,以及当用户从JList所基于的数组中删除或添加一个对象时?

Thank you. 谢谢。

Updates should be made to the ListModel, not the Array that was used to create the model. 应该对ListModel进行更新,而不是用于创建模型的Array。

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. 但是,如果要使用全新项刷新列表或更改项的顺序,则创建新的DefaultListModel并使用JList的setModel(...)方法更新视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM