Example usage for javax.swing JList JList

List of usage examples for javax.swing JList JList

Introduction

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

Prototype

public JList(final Vector<? extends E> listData) 

Source Link

Document

Constructs a JList that displays the elements in the specified Vector.

Usage

From source file:Main.java

public Main() {
    setLayout(new GridLayout(1, 2));
    String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" };
    JList<String> list = new JList<>(numbers);
    list.setVisibleRowCount(1);/*from   w w  w  .  ja v  a2 s. com*/
    list.addListSelectionListener(this);
    JScrollPane s = new JScrollPane(list);
    s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    add(s);
    list.setSelectedIndex(3);
}

From source file:Main.java

public Main() {
    super(new BorderLayout());
    String[] data = { "Math", "Computer", "Physics", "Chemistry" };
    list = new JList(data);
    list.addListSelectionListener(new SelectionHandler());
    JScrollPane jsp = new JScrollPane(list);
    this.add(jsp, BorderLayout.CENTER);
}

From source file:SimpleList.java

public SimpleList() {
    super("Simple Swing List");
    setSize(500, 240);//w  ww . j  a  v  a2  s . c o  m

    String[] item = { "First", "Second", "Third" };

    list = new JList(item);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add(list);
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    WindowListener exit = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(exit);

    setVisible(true);
}

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

    list.setSelectionModel(m);

    m.removeSelectionInterval(1, 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. co m*/
    });

    list.setSelectionModel(m);

    ListSelectionListener[] lis = m.getListSelectionListeners();

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

    list.setSelectionModel(m);

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

    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   ww w  . jav  a 2s  .c om*/
    });

    list.setSelectionModel(m);

    m.removeIndexInterval(1, 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());
        }//ww  w  .  j  a v  a2  s . c o  m
    });

    list.setSelectionModel(m);

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

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

    list.setSelectionModel(m);

    System.out.println(m.isSelectedIndex(0));

    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);

    ListSelectionListener[] lsls = (ListSelectionListener[]) (m.getListeners(ListSelectionListener.class));

    add(pane, BorderLayout.NORTH);
}