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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:37:58  来源:igfitidea点击:

DefaultListModel in Java

javaswinglistuser-interfacedefaultlistmodel

提问by Naruto

What is DefaultListModelin Java? and What is its purpose? I tried to google it but didn't get any proper explanation for it!

什么是DefaultListModelJava中?它的目的是什么?我试图用谷歌搜索它,但没有得到任何正确的解释!

采纳答案by MadProgrammer

DefaultListModelis a implementation of the ListModelthat extends from AbstractListModel.

DefaultListModelListModel从 扩展的的实现AbstractListModel

Internally, it is backed by Listimplementation.

在内部,它得到List实施的支持。

It's intention is to provide a simple implementation of the ListModelthat you can use for modelling simple data models where having to extend from the AbstractListModelor implement the ListModelinterface 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 Min MVC.

Swings 遵循 MVC,而DefaultListModel在MVC发挥其作用M

There are 3 ways to create model:

创建模型有3种方式:

  • DefaultListModel

    Everything is pretty much taken care of by language framework.

  • AbstractListModel

    You manage the data and invoke the "fire" methods. For this approach, you must subclass AbstractListModeland implement the getSizeand getElementAtmethods inherited from the ListModelinterface.

  • ListModel

    You manage everything.

  • 默认列表模型

    一切都由语言框架处理。

  • 抽象列表模型

    您管理数据并调用“fire”方法。对于这种方法,您必须子类化AbstractListModel并实现从接口继承的getSizegetElementAt方法ListModel

  • 列表模型

    你管理一切。

回答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