Example usage for javax.swing DefaultListSelectionModel setAnchorSelectionIndex

List of usage examples for javax.swing DefaultListSelectionModel setAnchorSelectionIndex

Introduction

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

Prototype

public void setAnchorSelectionIndex(int anchorIndex) 

Source Link

Document

Set the anchor selection index, leaving all selection values unchanged.

Usage

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());

    list = new JList(label);
    JScrollPane pane = new JScrollPane(list);

    DefaultListSelectionModel m = new DefaultListSelectionModel();

    m.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            System.out.println(e.toString());
        }/*from   w  w w.  j  a  va2  s.  c  om*/
    });

    list.setSelectionModel(m);

    m.setAnchorSelectionIndex(1);

    add(pane, BorderLayout.NORTH);
}