@Override public void setModel(ListModel model) { super.setModel(model); if (getCheckBoxListSelectionModel() != null) { getCheckBoxListSelectionModel().clearSelection(); } }
/** * 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(); }
@Override public void actionPerformed(ActionEvent e) { selectAll.setSelected(false); selectAll.setEnabled(true); selectNone.setEnabled(false); productsList.getCheckBoxListSelectionModel().clearSelection(); } });
@Override public void actionPerformed(ActionEvent e) { selectAll.setSelected(false); selectAll.setEnabled(true); selectNone.setEnabled(false); productsList.getCheckBoxListSelectionModel().clearSelection(); } });
public void clearCheckBoxListSelection() { getCheckBoxListSelectionModel().clearSelection(); }
@Override public void actionPerformed(ActionEvent e) { selectNone.setSelected(false); selectAll.setEnabled(false); selectNone.setEnabled(true); productsList.getCheckBoxListSelectionModel().setSelectionInterval(0, productsList.getModel().getSize() - 1); } });
@Override public void actionPerformed(ActionEvent e) { selectNone.setSelected(false); selectAll.setEnabled(false); selectNone.setEnabled(true); productsList.getCheckBoxListSelectionModel().setSelectionInterval(0, productsList.getModel().getSize() - 1); } });
/** * 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); }
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 void propertyChange(PropertyChangeEvent evt) { if (evt.getOldValue() instanceof ListModel) { ((ListModel) evt.getOldValue()).removeListDataListener(this); } if (evt.getNewValue() instanceof ListModel) { _list.getCheckBoxListSelectionModel().setModel((ListModel) evt.getNewValue()); ((ListModel) evt.getNewValue()).addListDataListener(this); } }
/** * 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); } }
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; }
/** * Selects a single cell and clear all other selections. * * @param index the index of the one cell to select * @see ListSelectionModel#setSelectionInterval * @see #isSelectedIndex * @see #addListSelectionListener */ public void setCheckBoxListSelectedIndex(int index) { if (index >= 0 && index < getModel().getSize()) { getCheckBoxListSelectionModel().setSelectionInterval(index, index); } }
/** * Deselects a single cell. * * @param index the index of the one cell to select * @see ListSelectionModel#setSelectionInterval * @see #isSelectedIndex * @see #addListSelectionListener */ public void removeCheckBoxListSelectedIndex(int index) { if (index >= 0 && index < getModel().getSize()) { getCheckBoxListSelectionModel().removeSelectionInterval(index, index); } }
/** * Deselects all objects in this list. */ public void selectNone() { if (getModel().getSize() > 0) { getCheckBoxListSelectionModel().removeIndexInterval(0, getModel().getSize() - 1); } }
/** * Selects all objects in this list. */ public void selectAll() { if (getModel().getSize() > 0) { getCheckBoxListSelectionModel().setSelectionInterval(0, getModel().getSize() - 1); } }
private void updatePane() { variableList.getCheckBoxListSelectionModel().removeListSelectionListener(checkBoxSelectionListener); variableList.setModel(model); variableList.setCheckBoxListSelectedIndices(getSelectedIndices(model)); final CheckBoxListSelectionModel selectionModel = variableList.getCheckBoxListSelectionModel(); selectionModel.addListSelectionListener(checkBoxSelectionListener); }
public void intervalAdded(ListDataEvent e) { int minIndex = Math.min(e.getIndex0(), e.getIndex1()); int maxIndex = Math.max(e.getIndex0(), e.getIndex1()); /* Sync the SelectionModel with the DataModel. */ ListSelectionModel listSelectionModel = _list.getCheckBoxListSelectionModel(); if (listSelectionModel != null) { listSelectionModel.insertIndexInterval(minIndex, maxIndex - minIndex + 1, true); } }
public void intervalRemoved(ListDataEvent e) { /* Sync the SelectionModel with the DataModel. */ ListSelectionModel listSelectionModel = _list.getCheckBoxListSelectionModel(); if (listSelectionModel != null) { listSelectionModel.removeIndexInterval(e.getIndex0(), e.getIndex1()); } }
@Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final CheckBoxListSelectionModel selectionModel = variableList.getCheckBoxListSelectionModel(); for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) { model.setSelectedVariableAt(i, selectionModel.isSelectedIndex(i)); } } } }