Java Swing更新JList [英] Java Swing Updating JList

查看:142
本文介绍了Java Swing更新JList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

谢谢。

推荐答案

应该更新ListModel,而不是Array用于创建模型。

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

但是,如果要使用全新项目刷新列表或更改项目的顺序,则创建新的DefaultListModel并使用JList的setModel(...)方法更新视图。

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.

这篇关于Java Swing更新JList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆