DefaultListModel Class
Package: javax.swing
DefaultListModel
provides a simple implementation of a list model, which can be used to manage items displayed by a JList
control.
Constructor
Constructor |
Description |
|
Creates a new list model object |
Methods
Method |
Description |
|
Adds an element at the specified position |
|
Adds an element to the end of the list |
|
Removes all elements from the list |
|
Returns |
|
Returns the first element in the list |
|
Returns the element at the specified location |
|
Returns |
|
Returns the last element in the list |
|
Removes the element from the specified position in the list |
|
Removes the specified element from the list |
|
Returns the number of elements in the list |
|
Returns an array containing each element in the list |
When you create the default data model, it’s empty, but you can call the add
or addElement
method to add elements to the list, as in this example:
Get Java For Dummies Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.