Example usage for javax.swing ListModel getSize

List of usage examples for javax.swing ListModel getSize

Introduction

In this page you can find the example usage for javax.swing ListModel getSize.

Prototype

int getSize();

Source Link

Document

Returns the length of the list.

Usage

From source file:Main.java

public static java.util.List getListData(JList jlist) {
    java.util.List out = new ArrayList();
    ListModel model = jlist.getModel();
    for (int i = 0; i < model.getSize(); i++)
        out.add(model.getElementAt(i));//from  ww w . ja  v a  2s  .c o  m
    return out;
}

From source file:Main.java

public static ArrayList listModelToList(ListModel listmodel) {
    ArrayList togo = new ArrayList();
    for (int i = 0; i < listmodel.getSize(); ++i) {
        togo.add(listmodel.getElementAt(i));
    }//from  w w  w.j  a v a  2  s  .  c o  m
    return togo;
}

From source file:Main.java

public static <T extends Object> T[] extendModel(ListModel selected, T[] extras, Class<T> type) {

    int selectedSize = selected.getSize();
    int extraSize = extras.length;
    @SuppressWarnings("unchecked")
    T[] augmented = (T[]) Array.newInstance(type, selectedSize + extraSize);

    // copy current
    for (int i = 0; i < selectedSize; i++) {
        augmented[i] = type.cast(selected.getElementAt(i));
    }//from  ww w .ja  v a2 s  .c  o  m
    // augment
    for (int i = 0; i < extraSize; i++) {
        augmented[selectedSize + i] = extras[i];
    }
    return augmented;
}

From source file:Main.java

public static <T extends Object> List<T> asList(ListModel listModel, Class<T> type) {

    List<T> res = new ArrayList<T>();
    for (int i = 0; i < listModel.getSize(); i++) {
        res.add(type.cast(listModel.getElementAt(i)));
    }//from  w w  w  .  jav  a 2  s.  c  om
    return res;
}

From source file:Main.java

public static List<String> listModelToList(ListModel<String> modelo) {
    List<String> result = new ArrayList<>();

    for (int i = 0; i < modelo.getSize(); i++) {
        result.add(modelo.getElementAt(i));
    }/*from  w ww  .ja  va2  s.c o m*/

    return result;
}

From source file:Main.java

public static int seachList(JList list, String match, int startIndex, boolean ingoreCase) {
    if (list == null || isStrEmpty(match) || list.getModel().getSize() <= 0 || startIndex < 0
            || startIndex >= list.getModel().getSize()) {
        return -1;
    }/* w  w  w  . ja  v a2  s .c o m*/
    ListModel model = list.getModel();
    int searchCount = 0;
    for (; startIndex < model.getSize(); startIndex++) {
        if (ingoreCase) {
            if (model.getElementAt(startIndex).toString().toUpperCase().indexOf(match.toUpperCase()) >= 0) {
                return startIndex;
            }
        } else {
            if (model.getElementAt(startIndex).toString().indexOf(match) >= 0) {
                return startIndex;
            }
        }

        searchCount++;
        if (searchCount >= model.getSize()) {
            return -1;
        }
        if (startIndex >= model.getSize() - 1) {
            startIndex = -1;
        }
    }
    return -1;
}

From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java

private static void updateListModel(JList list, List<?> newContents) {
    if (newContents == null) {
        newContents = ImmutableList.of();
    }/*from w  w w .j  a  v  a  2  s.c  o m*/
    ListModel oldModel = list.getModel();
    List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize());
    for (int i = 0; i < oldModel.getSize(); i++) {
        old.add(oldModel.getElementAt(i));
    }
    if (old.equals(newContents)) {
        return;
    }
    Object[] selected = list.getSelectedValues();
    DefaultListModel listModel = new DefaultListModel();
    for (Object obj : newContents) {
        listModel.addElement(obj);
    }
    list.setModel(listModel);
    List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length);
    Set<Object> selectedSet = Sets.newHashSet(selected);
    for (int i = 0; i < listModel.size(); i++) {
        if (selectedSet.contains(listModel.elementAt(i))) {
            newIndices.add(i);
        }
    }
    list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0])));
}

From source file:SelectionHandler.java

private void removeFromSource(String item) {
    ListModel model = source.getModel();
    Vector listData = new Vector();
    for (int i = 0; i < model.getSize(); i++) {
        listData.addElement(model.getElementAt(i));
    }/*from ww  w. j  a  v  a 2s.  c o  m*/
    listData.removeElement(item);
    source.setListData(listData);
}

From source file:SelectionHandler.java

private void addToDestination(String item) {
    ListModel model = destination.getModel();
    Vector listData = new Vector();
    for (int i = 0; i < model.getSize(); i++) {
        listData.addElement(model.getElementAt(i));
    }// ww w  .  j  a  va2s  . c  om
    listData.addElement(item);
    destination.setListData(listData);
}

From source file:SortedListModel.java

private void fillListModel(SortedListModel model, ListModel newValues) {
    int size = newValues.getSize();
    for (int i = 0; i < size; i++) {
        model.add(newValues.getElementAt(i));
    }//  w ww .  j  a  v a 2 s. c  om
}