final DefaultListSelectionModel defaultListSelectionModel = new DefaultListSelectionModel(); treetable.setSelectionModel(defaultListSelectionModel); defaultListSelectionModel.setSelectionMode(SINGLE_SELECTION); defaultListSelectionModel.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) {
/** * If {@code updatingListSelectionModel} is false, this will * reset the selected paths from the selected rows in the list * selection model. */ private void updateSelectedPathsFromSelectedRows() { if (!updatingListSelectionModel) { updatingListSelectionModel = true; try { // This is way expensive, ListSelectionModel needs an // enumerator for iterating. final int min = listSelectionModel.getMinSelectionIndex(); final int max = listSelectionModel.getMaxSelectionIndex(); clearSelection(); if (min != -1 && max != -1) { for (int counter = min; counter <= max; counter++) { updateSelectedPathIfRowIsSelected(counter); } } } finally { updatingListSelectionModel = false; } } }
/** * If the row at given index is selected, selected paths are updated. * @param counter number of row. */ private void updateSelectedPathIfRowIsSelected(int counter) { if (listSelectionModel.isSelectedIndex(counter)) { final TreePath selPath = treeTable.getTree().getPathForRow(counter); if (selPath != null) { addSelectionPath(selPath); } } }
/** * If <code>updatingListSelectionModel</code> is false, this will * reset the selected paths from the selected rows in the list selection * model. */ protected void updateSelectedPathsFromSelectedRows() { if (!updatingListSelectionModel) { updatingListSelectionModel = true; try { // This is way expensive, ListSelectionModel needs an // enumerator for iterating. int min = listSelectionModel.getMinSelectionIndex(); int max = listSelectionModel.getMaxSelectionIndex(); clearSelection(); if ((min != -1) && (max != -1)) { for (int counter = min; counter <= max; counter++) { if (listSelectionModel.isSelectedIndex(counter)) { TreePath selPath = tree.getPathForRow(counter); if (selPath != null) { addSelectionPath(selPath); } } } } } finally { updatingListSelectionModel = false; } } }
updatingListSelectionModel = true; try { if (listSelectionModel.isSelectionEmpty()) { clearSelection(); } else { int min = listSelectionModel.getMinSelectionIndex(); int max = listSelectionModel.getMaxSelectionIndex(); if (listSelectionModel.isSelectedIndex(counter)) { TreePath selPath = renderer.getPathForRow( counter);
public ListSelectionModel getTableSelectionModel() { if (selectionModel_ == null) { selectionModel_= new DefaultListSelectionModel(); } return selectionModel_; }
/** * Renvoie la liste de points de <code>_p </code> contenus dans le polygone <code>_polyRef</code>. * * @return null si aucun point n'appartient a <code>_polyRef</code>. */ public static final DefaultListSelectionModel pointsSelectionnes(final GrPolygone _poly, final GrPolygone _polyolyRef) { final GrBoite polyRefBoite = _polyolyRef.boite(); if (!polyRefBoite.intersectXY(_poly.boite())) { return null; } final int nb = _poly.nombre() - 1; GrPoint p; final DefaultListSelectionModel r = new DefaultListSelectionModel(); r.setValueIsAdjusting(true); for (int i = nb; i >= 0; i--) { p = _poly.sommet(i); if (p == null) { continue; } if (polyRefBoite.contientXY(p) && _polyolyRef.contientXY(p)) { r.addSelectionInterval(i, i); } } r.setValueIsAdjusting(false); return r.isSelectionEmpty() ? null : r; }
DefaultListSelectionModel searchResultSelectionModel = new DefaultListSelectionModel(); searchResultSelectionModel .setSelectionMode(ListSelectionModel.SINGLE_SELECTION); Document searchInput = new PlainDocument();
/** Creates a new instance of TaskModel */ public TaskModel() { selectionModel = new DefaultListSelectionModel(); model = new DefaultListModel(); dataListeners = new LinkedHashSet<ListDataListener>(); selectionListeners = new LinkedHashSet<ListSelectionListener>(); TaskListener list = new TaskListener(); model.addListDataListener(list); selectionModel.addListSelectionListener(list); }
JTable table = new JTable(); // your table instance TableModel dataModel = new DefaultTableModel(); // table model DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); //table selection model table.setModel(dataModel); table.setSelectionModel(selectionModel); int desiredRow = 0; // row which you want to deselect selectionModel.removeSelectionInterval(desiredRow, desiredRow); // Removing selection for desired row
protected void updateFromDja() { if (isInternalUpdate_) { return; } isInternalUpdate_ = true; for (int i = getSize() - 1; i >= 0; i--) { boolean selected = isSelectedInDjaVector(i); if (selected && !model_.isSelectedIndex(i)) { model_.addSelectionInterval(i, i); } else if (!selected && model_.isSelectedIndex(i)) { model_.removeSelectionInterval(i, i); } } isInternalUpdate_ = false; }
@Override public int[] getSelectedColumns() { int index = dlsm.getMinSelectionIndex(); if (index == -1) { return new int[] {}; } return new int[] { index }; }
/** * Updates the list of available token properties. */ private void updateProperties() { ArrayList<TokenProperty> sorted = new ArrayList<TokenProperty>(this.canvas.getUsedProperties()); Collections.sort(sorted); int index = 0; listModel.clear(); listModel = new DefaultListModel(); DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); for (TokenProperty p : sorted) { listModel.addElement(p); if (!this.tokenFilter.getForbiddenTokenProperties().contains(p) && !list.isSelectedIndex(index)) selectionModel.addSelectionInterval(index, index); ++index; } list.setModel(listModel); list.setSelectionModel(selectionModel); }
public void setSelectionInterval(int index0, int index1) { if(isSelectedIndex(index0)) { super.removeSelectionInterval(index0, index1); } else { super.setSelectionInterval(index0, index1); } } });
@Override public int getMinSelectionIndex() { int index = super.getMinSelectionIndex(); if (getAllEntryIndex() < 0) { return index; } if (super.isSelectedIndex(getAllEntryIndex()) && getAllEntryIndex() == 0) { return 1; } return index; }
void hiddenSetSelectionInterval(final int index) { super.setSelectionInterval(index, index); } }
@Override public void setSelectionInterval(int index0, int index1) { // Toggle only one element while the user is dragging the mouse if (!gestureStarted) { if (isSelectedIndex(index0)) { super.removeSelectionInterval(index0, index1); } else { if (getSelectionMode() == SINGLE_SELECTION) { super.setSelectionInterval(index0, index1); } else { super.addSelectionInterval(index0, index1); } } } // Disable toggling till the adjusting is over, or keep it // enabled in case setSelectionInterval was called directly. gestureStarted = getValueIsAdjusting(); }
public void setSelectionInterval(int index0, int index1) { if (index0==index1) { if (isSelectedIndex(index0)) { removeSelectionInterval(index0, index0); return; public void addSelectionInterval(int index0, int index1) { if (index0==index1) { if (isSelectedIndex(index0)) { removeSelectionInterval(index0, index0); return;
public void addSelectedItem(B toSelect) { Collection<B> oldValue = Lists.newArrayList(selectedValues); selectedValues.add(toSelect); int index = selectedValues.indexOf(toSelect); super.addSelectionInterval(index, index); fireSelectionAdded(Lists.newArrayList(toSelect)); firePropertyChange(PROPERTY_SELECTED_VALUE, oldValue, selectedValues); }
/** * Respond to a change in the view selection by updating the view selection. * * @param firstIndex the first view index that changed, inclusive * @param lastIndex the last view index that changed, inclusive */ private void mapTowardsModel(int firstIndex, int lastIndex) { int safeFirstIndex = Math.max(0, firstIndex); // Fix for #855-swingx: JXList AIOOB on select after remove/add data items int safeLastIndex = getSafeLastIndex(lastIndex); for (int i = safeFirstIndex; i <= safeLastIndex; i++) { int modelIndex = convertToModel(i); if (viewSelection.isSelectedIndex(i)) { modelSelection.addSelectionInterval(modelIndex, modelIndex); } else { modelSelection.removeSelectionInterval(modelIndex, modelIndex); } } int lead = viewSelection.getLeadSelectionIndex(); if (lead >= 0) { modelSelection.moveLeadSelectionIndex(convertToModel(lead)); } }