Java Utililty Methods JList Model

List of utility methods to do JList Model

Description

The list of methods to do JList Model are organized into topic(s).

Method

booleanhasOnlyValue(final ListModel model, final Object value)
Returns true if the given model is not null and contains only the given value.
return model != null && model.getSize() == 1 && model.getElementAt(0) == value;
int[]indexesOf(DefaultListModel model, String sa[])
Returns all the indexes of elements in a model.
int[] ia = new int[sa.length];
for (int x = 0; x < sa.length; x++)
    ia[x] = model.indexOf(sa[x]);
return ia;
intindexOf(Object obj, ListModel model)
index Of
return indexOf(obj, 0, model);
DefaultListModellistAsListModel(ArrayList list)
Converts an ArrayList into a DefaultListModel object.
DefaultListModel<T> ret = new DefaultListModel<>();
for (T elem : list) {
    ret.addElement(elem);
return ret;
booleanlistModelEquals(final ListModel lm, final ListModel lm2)
list Model Equals
for (int i = 0; i < lm.getSize(); i++) {
    if (!lm.getElementAt(i).equals(lm2.getElementAt(i)))
        return false;
return true;
voidremove(final DefaultListModel list, final int[] indices)
Removes the given elements from the given list.
int i = indices.length;
if (i != 0) {
    Arrays.sort(indices);
    int upper = indices[--i];
    int lower = upper;
    while (i != 0) {
        int previous = indices[--i];
        if (previous != lower - 1) {
...
voidremoveAll(DefaultListModel m, List o)
Removes all entries of the List from a DefaultListModel
for (int i = 0; i < o.size(); i++) {
    m.removeElement(o.get(i));
voidremoveFromList(String path, DefaultListModel model, JList list)
remove From List
if (path != null) {
    model.removeElement(path);
    list.setModel(model);
voidsetListModel(ListModel model, JList list)
set List Model
list.setModel(model);
if (model.getSize() > 0) {
    list.setSelectedIndex(0);
DefaultListModeltoDefaultListModel(ArrayList list)
to Default List Model
DefaultListModel listModel = new DefaultListModel();
for (int i = 0; i < list.size(); i++) {
    listModel.addElement(list.get(i));
return listModel;