/** * Returns the first selected index; returns -1 if there is no selected item. * * @return the value of <code>getMinSelectionIndex</code> * @see #getMinSelectionIndex * @see #addListSelectionListener */ public int getCheckBoxListSelectedIndex() { return getCheckBoxListSelectionModel().getMinSelectionIndex(); }
/** * Returns the first selected value, or <code>null</code> if the selection is empty. * * @return the first selected value * @see #getMinSelectionIndex * @see #getModel * @see #addListSelectionListener */ public Object getCheckBoxListSelectedValue() { int i = getCheckBoxListSelectionModel().getMinSelectionIndex(); return (i == -1) ? null : getModel().getElementAt(i); }
ListModel model = getModel(); int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex();
/** * Returns an array of all of the selected indices in increasing order. * * @return all of the selected indices, in increasing order * @see #removeSelectionInterval * @see #addListSelectionListener */ public int[] getCheckBoxListSelectedIndices() { CheckBoxListSelectionModel listSelectionModel = getCheckBoxListSelectionModel(); int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex(); if ((iMin < 0) || (iMax < 0)) { return new int[0]; } int[] temp = new int[1 + (iMax - iMin)]; int n = 0; for (int i = iMin; i <= iMax; i++) { if (listSelectionModel.isAllEntryConsidered() && i == listSelectionModel.getAllEntryIndex()) { continue; } if (listSelectionModel.isSelectedIndex(i)) { temp[n] = i; n++; } } int[] indices = new int[n]; System.arraycopy(temp, 0, indices, 0, n); return indices; }