Java JList 模型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2893052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java JList model
提问by palAlaa
How can I make a list model from a JList
in order to be able to insert an item into it.
I want to use this method: addElement(java.lang.Object item)
如何从 a 制作列表模型JList
以便能够将项目插入其中。我想用这个方法:addElement(java.lang.Object item)
I found an explanation here, but the problem is that ListModel
is an interface
and even if I write an implementation and override its method, I can't use the addElement()
method
我在这里找到了一个解释,但问题是这ListModel
是一个接口,即使我编写了一个实现并覆盖了它的方法,我也无法使用该addElement()
方法
采纳答案by Michael Mrozek
Java provides implementations of ListModel
already, like DefaultListModel
, that you can instantiate and use
Java 提供了ListModel
已经的实现,例如DefaultListModel
,您可以实例化和使用
For example:
例如:
final DefaultListModel model = new DefaultListModel();
model.addElement("one");
model.addElement("two");
model.addElement("three");
final JList list = new JList(model);
回答by npinti
Check out this Sun Tutorial. Contains example on how to add lists to a JList
查看此Sun 教程。包含有关如何将列表添加到 JList 的示例