List of utility methods to do JList Model
boolean | hasOnlyValue(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; |
int | indexOf(Object obj, ListModel model) index Of return indexOf(obj, 0, model);
|
DefaultListModel | listAsListModel(ArrayList Converts an ArrayList into a DefaultListModel object. DefaultListModel<T> ret = new DefaultListModel<>(); for (T elem : list) { ret.addElement(elem); return ret; |
boolean | listModelEquals(final ListModel list Model Equals for (int i = 0; i < lm.getSize(); i++) { if (!lm.getElementAt(i).equals(lm2.getElementAt(i))) return false; return true; |
void | remove(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) { ... |
void | removeAll(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)); |
void | removeFromList(String path, DefaultListModel model, JList list) remove From List if (path != null) {
model.removeElement(path);
list.setModel(model);
|
void | setListModel(ListModel model, JList list) set List Model list.setModel(model);
if (model.getSize() > 0) {
list.setSelectedIndex(0);
|
DefaultListModel | toDefaultListModel(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; |