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:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access