/** * Selects the specified object from the list and keep all previous selections. * * @param anObject the object to be selected * @param shouldScroll true if the list should scroll to display the selected object, if one * exists; otherwise false */ public void addCheckBoxListSelectedValue(Object anObject, boolean shouldScroll) { ListModel model = getModel(); int i, c; if (anObject != null) { for (i = 0, c = model.getSize(); i < c; i++) if (anObject.equals(model.getElementAt(i))) { addCheckBoxListSelectedIndex(i); if (shouldScroll) ensureIndexIsVisible(i); repaint(); /** FIX-ME setSelectedIndex does not redraw all the time with the basic l&f* */ return; } } else { for (i = 0, c = model.getSize(); i < c; i++) { if (model.getElementAt(i) == null) { addCheckBoxListSelectedIndex(i); if (shouldScroll) ensureIndexIsVisible(i); repaint(); /** FIX-ME setSelectedIndex does not redraw all the time with the basic l&f* */ return; } } } }
/** * Selects the specified objects from the list and keep all previous selections. * * @param objects the objects to be selected */ public void addCheckBoxListSelectedValues(Object[] objects) { if (objects != null) { Map<Object, String> map = new HashMap<Object, String>(); for (Object o : objects) { map.put(o, ""); } int i, c; ListModel model = getModel(); boolean changed = false; for (i = 0, c = model.getSize(); i < c; i++) if (map.get(model.getElementAt(i)) != null) { addCheckBoxListSelectedIndex(i); changed = true; } if (changed) { repaint(); } map.clear(); } }