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 in Java
25.1k Views Asked by Naruto At
3
There are 3 best solutions below
0
On
Here's a link to an example of using ListModel and DefaultListModel, its the second link when you google it.
http://www.java2s.com/Code/Java/Swing-JFC/AnexampleofJListwithaDefaultListModel.htm
1
On
It works as a Model (predefined) for JList
Swings follows MVC and DefaultListModel plays its part as M in MVC.
There are 3 ways to create model:
-
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
AbstractListModeland implement thegetSizeandgetElementAtmethods inherited from theListModelinterface. -
You manage everything.
DefaultListModelis a implementation of theListModelthat extends fromAbstractListModel.Internally, it is backed by
Listimplementation.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 theAbstractListModelor implement theListModelinterface would be overkill for accomplishing the same task