DefaultListModel in Java

What is DefaultListModel in Java? and what is its purpose? I tried to do this, but did not get the right explanation!

+6
source share
3 answers

DefaultListModel is an implementation of ListModel that extends from AbstractListModel .

Internally, it is supported by List .

The goal is to provide a simple ListModel implementation that you can use to simulate simple data models when the need for an extension from AbstractListModel or an implementation of the ListModel would be unnecessary to perform the same task

+4
source

It works as Model (predefined) for JList

Swings follow MVC, and DefaultListModel plays its role as M in MVC.

There are 3 ways to create a model:

  • DefaultListModel

    All pretty much takes care of the language environment.

  • AbstractListModel

    You control the data and cause the fire. For this approach, you must subclass AbstractListModel and implement the getSize and getElementAt methods inherited from the ListModel interface.

  • Listmodel

    You all control.

+7
source

Here is a link to an example using ListModel and DefaultListModel, its second link when you google it.

http://www.java2s.com/Code/Java/Swing-JFC/AnexampleofJListwithaDefaultListModel.htm

+5
source

All Articles