Java Code Examples for javax.swing.ListSelectionModel#setAnchorSelectionIndex()

The following examples show how to use javax.swing.ListSelectionModel#setAnchorSelectionIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Set the lead and anchor without affecting selection.
 */
public static void setLeadAnchorWithoutSelection(ListSelectionModel model,
                                                 int lead, int anchor) {
    if (anchor == -1) {
        anchor = lead;
    }
    if (lead == -1) {
        model.setAnchorSelectionIndex(-1);
        model.setLeadSelectionIndex(-1);
    } else {
        if (model.isSelectedIndex(lead)) {
            model.addSelectionInterval(lead, lead);
        } else {
            model.removeSelectionInterval(lead, lead);
        }
        model.setAnchorSelectionIndex(anchor);
    }
}
 
Example 2
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/**
    * Invokes <code>getNextIndex</code> to determine the next index
    * to select. If the index is valid (not -1 and < size of the model),
    * this will either: move the selection to the new index if
    * the selectionType == CHANGE_SELECTION, move the lead to the
    * new index if selectionType == CHANGE_LEAD, otherwise the
    * selection is extend from the anchor to the new index and the
    * lead is set to the new index.
    */
   public void actionPerformed(ActionEvent e) {
     int index = getNextIndex();
     if (index >= 0 && index < list.getModel().getSize()) {
ListSelectionModel lsm = list.getSelectionModel();

if (selectionType == EXTEND_SELECTION) {
  int anchor = lsm.getAnchorSelectionIndex();
  if (anchor == -1) {
    anchor = index;
  }
  list.setSelectionInterval(anchor, index);
  lsm.setAnchorSelectionIndex(anchor);
  lsm.setLeadSelectionIndex(index);
}
else if (selectionType == CHANGE_SELECTION) {
  list.setSelectedIndex(index);
}
else {
  lsm.setLeadSelectionIndex(index);
}
ensureIndexIsVisible(index);
     }
   }
 
Example 3
Source File: OutlineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setTo(ListSelectionModel sm) {
    sm.clearSelection();
    sm.setSelectionMode(selectionMode);
    for (int[] itv : intervals) {
        sm.addSelectionInterval(itv[0], itv[1]);
    }
    sm.setAnchorSelectionIndex(anchor);
    sm.setLeadSelectionIndex(lead);
}