@Override public void mousePressed(MouseEvent e) { PanelTable.this.tableValues.requestFocusInWindow(); if (SwingUtilities.isRightMouseButton(e)) { /** * Keep selection when multiple cells are selected, * move focus only */ Point p = e.getPoint(); int rowNumber = PanelTable.this.tableValues.rowAtPoint(p); int colNumber = PanelTable.this.tableValues.columnAtPoint(p); DefaultListSelectionModel modelRow = (DefaultListSelectionModel) PanelTable.this.tableValues .getSelectionModel(); DefaultListSelectionModel modelColumn = (DefaultListSelectionModel) PanelTable.this.tableValues .getColumnModel().getSelectionModel(); modelRow.moveLeadSelectionIndex(rowNumber); modelColumn.moveLeadSelectionIndex(colNumber); } } });
@Override public void mousePressed(MouseEvent e) { PanelConsoles.this.networkTable.requestFocusInWindow(); // move selected row and place cursor on focused cell if (SwingUtilities.isRightMouseButton(e)) { Point p = e.getPoint(); // get the row index that contains that coordinate int rowNumber = PanelConsoles.this.networkTable.rowAtPoint(p); int colNumber = PanelConsoles.this.networkTable.columnAtPoint(p); // Get the ListSelectionModel of the JTable DefaultListSelectionModel model = (DefaultListSelectionModel) PanelConsoles.this.networkTable.getSelectionModel(); DefaultListSelectionModel model2 = (DefaultListSelectionModel) PanelConsoles.this.networkTable.getColumnModel().getSelectionModel(); PanelConsoles.this.networkTable.setRowSelectionInterval(rowNumber, rowNumber); model.moveLeadSelectionIndex(rowNumber); model2.moveLeadSelectionIndex(colNumber); } } });
public void clearSelection() { if (listSelectionModel != null) { listSelectionModel.clearSelection(); if (listSelectionModel instanceof DefaultListSelectionModel) { ((DefaultListSelectionModel) listSelectionModel).moveLeadSelectionIndex(0); listSelectionModel.setAnchorSelectionIndex(0); } } }
((DefaultListSelectionModel)lsm).moveLeadSelectionIndex(index);
((DefaultListSelectionModel)lsm).moveLeadSelectionIndex(index);
((DefaultListSelectionModel)lsm).moveLeadSelectionIndex(index);
/** * 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)); } }
((DefaultListSelectionModel)lsm).moveLeadSelectionIndex(index);
/** * Populate view selection from model selection. */ private void mapTowardsModel() { if(modelSelection == null) return; clearModelSelection(); int[] selected = getSelectedRows(viewSelection); for (int i = 0; i < selected.length; i++) { int modelIndex = convertToModel(selected[i]); modelSelection.addSelectionInterval(modelIndex, modelIndex); } if (selected.length > 0) { // convert lead selection index to model coordinates modelSelection.moveLeadSelectionIndex(convertToModel(viewSelection.getLeadSelectionIndex())); } }
((DefaultListSelectionModel) viewSelection).moveLeadSelectionIndex(lead); } else {
((DefaultListSelectionModel) listSelectionModel).moveLeadSelectionIndex(lead); listSelectionModel.setAnchorSelectionIndex(anchor);