Example usage for javax.swing DefaultListSelectionModel addSelectionInterval

List of usage examples for javax.swing DefaultListSelectionModel addSelectionInterval

Introduction

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

Prototype

public void addSelectionInterval(int index0, int index1) 

Source Link

Document

Changes the selection to be the set union of the current selection and the indices between index0 and index1 inclusive.

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.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.setLeadAnchorNotificationEnabled(false);
    list.setSelectionModel(m);//  w w  w . ja v  a  2s.  c  o m

    m.addSelectionInterval(1, 1);

    add(pane, BorderLayout.NORTH);
}