Example usage for javax.swing ListSelectionModel setAnchorSelectionIndex

List of usage examples for javax.swing ListSelectionModel setAnchorSelectionIndex

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel setAnchorSelectionIndex.

Prototype

void setAnchorSelectionIndex(int index);

Source Link

Document

Set the anchor selection index.

Usage

From source file:Main.java

/**
 * Set the lead and anchor without affecting selection.
 *///www  . j a va2 s.  c  o m
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);
    }
}