DefaultListModel in Java

Naruto picture Naruto · Oct 30, 2012 · Viewed 20.3k times · Source

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

Answer

Azodious picture Azodious · Oct 30, 2012

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:

  • 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 AbstractListModel and implement the getSize and getElementAt methods inherited from the ListModel interface.

  • ListModel

    You manage everything.