Example usage for javax.swing.event ListSelectionListener ListSelectionListener

List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener

Introduction

In this page you can find the example usage for javax.swing.event ListSelectionListener ListSelectionListener.

Prototype

ListSelectionListener

Source Link

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  va  2s.  c o m*/
    });

    list.setSelectionModel(m);

    m.setAnchorSelectionIndex(1);

    add(pane, BorderLayout.NORTH);
}

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());
        }/* w w  w . j av  a 2  s  .c o  m*/
    });

    list.setSelectionModel(m);

    m.moveLeadSelectionIndex(1);

    add(pane, BorderLayout.NORTH);
}

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());
        }/*w w w  . j  a v a2 s.  c om*/
    });

    list.setSelectionModel(m);

    System.out.println(m.isSelectionEmpty());

    add(pane, BorderLayout.NORTH);
}

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  av  a2  s  .  com*/
    });

    list.setSelectionModel(m);

    System.out.println(m.isLeadAnchorNotificationEnabled());

    add(pane, BorderLayout.NORTH);
}

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());
        }//w ww . jav  a  2 s  .  co  m
    });

    list.setSelectionModel(m);

    m.setLeadSelectionIndex(1);

    add(pane, BorderLayout.NORTH);
}

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());
        }//  w  w  w . j  av a 2s. co  m
    });

    list.setSelectionModel(m);

    System.out.println(m.getMinSelectionIndex());

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

Main() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    ArrayList data = new ArrayList();
    data.add("Hi");
    data.add("Hello");
    data.add("Goodbye");
    list = new JList(data.toArray());
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());
        }/*from w  w  w.  j  a v a  2s .  com*/
    });
    cp.add(new JScrollPane(list), BorderLayout.CENTER);
}

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

    list.setSelectionModel(m);

    System.out.println(m.getValueIsAdjusting());

    add(pane, BorderLayout.NORTH);
}

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());
        }/*  w w w. ja  va2  s .  c o  m*/
    });

    list.setSelectionModel(m);

    System.out.println(m.getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

Main() {
    JFrame jfrm = new JFrame("Use JList");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(200, 160);//from   w w w  .j  a v  a 2 s.c  om
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jlst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jlst.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent le) {
            int idx = jlst.getSelectedIndex();
            if (idx != -1)
                System.out.println("Current selection: " + languages[idx]);
            else
                System.out.println("Please choose a language.");
        }
    });

    jfrm.add(new JScrollPane(jlst));
    jfrm.setSize(300, 300);
    jfrm.setVisible(true);
}