Java 中的 DefaultListModel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13136826/
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
DefaultListModel in Java
提问by Naruto
What is DefaultListModel
in Java? and What is its purpose?
I tried to google it but didn't get any proper explanation for it!
什么是DefaultListModel
Java中?它的目的是什么?我试图用谷歌搜索它,但没有得到任何正确的解释!
采纳答案by MadProgrammer
DefaultListModel
is a implementation of the ListModel
that extends from AbstractListModel
.
DefaultListModel
是ListModel
从 扩展的的实现AbstractListModel
。
Internally, it is backed by List
implementation.
在内部,它得到List
实施的支持。
It's intention is to provide a simple implementation of the ListModel
that you can use for modelling simple data models where having to extend from the AbstractListModel
or implement the ListModel
interface would be overkill for accomplishing the same task
它的目的是提供一个简单的实现ListModel
,您可以使用它来对简单的数据模型进行建模,其中必须扩展AbstractListModel
或实现ListModel
接口对于完成相同的任务来说是多余的
回答by Azodious
It works as a Model
(predefined) for JList
它作为Model
(预定义的)用于JList
Swings follows MVC and DefaultListModelplays its part as M
in MVC.
Swings 遵循 MVC,而DefaultListModel在MVC中发挥其作用M
。
There are 3 ways to create model:
创建模型有3种方式:
Everything is pretty much taken care of by language framework.
You manage the data and invoke the "fire" methods. For this approach, you must subclass
AbstractListModel
and implement thegetSize
andgetElementAt
methods inherited from theListModel
interface.You manage everything.
回答by deleted_user
Here's a link to an example of using ListModel and DefaultListModel, its the second link when you google it.
这是使用 ListModel 和 DefaultListModel 示例的链接,这是您在 google 上搜索时的第二个链接。
http://www.java2s.com/Code/Java/Swing-JFC/AnexampleofJListwithaDefaultListModel.htm
http://www.java2s.com/Code/Java/Swing-JFC/AnexampleofJListwithaDefaultListModel.htm