protected void toggleSelections() { int[] indices = _list.getSelectedIndices(); CheckBoxListSelectionModel selectionModel = _list.getCheckBoxListSelectionModel(); selectionModel.removeListSelectionListener(this); selectionModel.setValueIsAdjusting(true); try { if (indices.length > 0) { boolean selected = selectionModel.isSelectedIndex(indices[0]); for (int index : indices) { if (!_list.isCheckBoxEnabled(index)) { continue; } if (selected && selectionModel.isSelectedIndex(index)) { selectionModel.removeSelectionInterval(index, index); } else if (!selected && !selectionModel.isSelectedIndex(index)) { selectionModel.addSelectionInterval(index, index); } } } } finally { selectionModel.setValueIsAdjusting(false); selectionModel.addListSelectionListener(this); _list.repaint(); } }
public CheckBoxListSelectionModel(ListModel model) { _model = model; if (isAllEntryConsidered()) { _allEntryIndex = findAllEntryIndex(); _model.addListDataListener(this); } setSelectionMode(MULTIPLE_INTERVAL_SELECTION); }
@Override public void actionPerformed(ActionEvent e) { selectAll.setSelected(false); selectAll.setEnabled(true); selectNone.setEnabled(false); productsList.getCheckBoxListSelectionModel().clearSelection(); } });
private boolean unselectAll(int index0, int index1) { if (getAllEntryIndex() < 0) { return false; } if (index0 == getAllEntryIndex() || index1 == getAllEntryIndex()) { clearSelection(); return true; } else { return false; } }
private void selectAllIf() { if (getAllEntryIndex() < 0) { return; } for (int i = getModel().getSize() - 1; i >= 0; i--) { if (i != getAllEntryIndex() && !isSelectedIndex(i)) { return; } } super.addSelectionInterval(getAllEntryIndex(), getAllEntryIndex()); }
filterableList.getCheckBoxListSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); if (model.getSize() > 0) { filterableList.setPrototypeCellValue(model.getElementAt(0)); // Makes it much faster to determine the view's preferred size. filterableList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) {
/** * 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; }
productsList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {
boolean old = isSelectedIndex(index); boolean adjusting = getValueIsAdjusting(); super.setValueIsAdjusting(true); try { if (old) { removeSelectionInterval(index, index); addSelectionInterval(index + length, index + length);
private void configureComponents() { checkBoxList.getCheckBoxListSelectionModel().getModel().getElementAt(0); checkBoxList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) {
private void updatePane() { variableList.getCheckBoxListSelectionModel().removeListSelectionListener(checkBoxSelectionListener); variableList.setModel(model); variableList.setCheckBoxListSelectedIndices(getSelectedIndices(model)); final CheckBoxListSelectionModel selectionModel = variableList.getCheckBoxListSelectionModel(); selectionModel.addListSelectionListener(checkBoxSelectionListener); }
private boolean selectAll(int index0, int index1) { if (getAllEntryIndex() < 0) { return false; } if ((index0 == 0 && index1 == getModel().getSize() - 1) || (index1 == 0 && index0 == getModel().getSize() - 1)) { return false; } if ((index0 >= getAllEntryIndex() && index1 <= getAllEntryIndex()) || (index1 >= getAllEntryIndex() && index0 <= getAllEntryIndex())) { setSelectionInterval(0, getModel().getSize() - 1); return true; } else { return false; } }
@Override public void run() { final String text = maskNameSearchField.getText(); final DefaultListModel<Object> updatedListModel = new DefaultListModel<>(); List<Boolean> selected = new ArrayList<>(); int[] newIndexesInMaskNameList = new int[maskNameListModel.getSize()]; int counter = 0; for (int i = 0; i < maskNameListModel.getSize(); i++) { if (maskNameListModel.get(i).toLowerCase().contains(text.toLowerCase())) { updatedListModel.addElement(maskNameListModel.get(i)); if (indexesInMaskNameList[i] >= 0) { selected.add(maskNameList.getCheckBoxListSelectionModel().isSelectedIndex(indexesInMaskNameList[i])); } else { selected.add(false); } newIndexesInMaskNameList[i] = counter++; } else { newIndexesInMaskNameList[i] = -1; } } indexesInMaskNameList = newIndexesInMaskNameList; maskNameList.setModel(updatedListModel); for (int i = 0; i < selected.size(); i++) { if (selected.get(i)) { maskNameList.getCheckBoxListSelectionModel().addSelectionInterval(i, i); } } } });
List<Product> getSelectedProducts() { List<Product> selectedProducts = new ArrayList<>(); for (int i = 0; i < productsList.getModel().getSize(); i++) { if (productsList.getCheckBoxListSelectionModel().isSelectedIndex(i)) { selectedProducts.add((Product) productsList.getModel().getElementAt(i)); } } return selectedProducts; }
public CheckBoxListSelectionModel() { setSelectionMode(MULTIPLE_INTERVAL_SELECTION); }
/** * Selects a single cell and keeps all previous selections. * * @param index the index of the one cell to select * @see ListSelectionModel#setSelectionInterval * @see #isSelectedIndex * @see #addListSelectionListener */ public void addCheckBoxListSelectedIndex(int index) { if (index >= 0 && index < getModel().getSize()) { getCheckBoxListSelectionModel().addSelectionInterval(index, index); } }
@Override public void actionPerformed(ActionEvent e) { selectNone.setSelected(false); selectAll.setEnabled(false); selectNone.setEnabled(true); productsList.getCheckBoxListSelectionModel().setSelectionInterval(0, productsList.getModel().getSize() - 1); } });
maskNameList.getCheckBoxListSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); maskNameList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) {
ListModel model = getModel(); int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex(); int n = 0; for (int i = iMin; i <= iMax; i++) { if (listSelectionModel.isAllEntryConsidered() && i == listSelectionModel.getAllEntryIndex()) { continue; if (listSelectionModel.isSelectedIndex(i)) { temp[n] = model.getElementAt(i); n++;