Example usage for javax.swing DefaultListSelectionModel setLeadSelectionIndex

List of usage examples for javax.swing DefaultListSelectionModel setLeadSelectionIndex

Introduction

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

Prototype

public void setLeadSelectionIndex(int leadIndex) 

Source Link

Document

Sets the lead selection index, ensuring that values between the anchor and the new lead are either all selected or all deselected.

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   ww w.  j  a v  a 2 s  . c o  m
    });

    list.setSelectionModel(m);

    m.setLeadSelectionIndex(1);

    add(pane, BorderLayout.NORTH);
}