Example usage for javax.swing JList getSelectedValuesList

List of usage examples for javax.swing JList getSelectedValuesList

Introduction

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

Prototype

@BeanProperty(bound = false)
public List<E> getSelectedValuesList() 

Source Link

Document

Returns a list of all the selected items, in increasing order based on their indices in the list.

Usage

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1);//from  w  ww .  j  a v  a  2s .  com

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            List objs = jlist.getSelectedValuesList();
        }
    };
    jlist.addListSelectionListener(listSelectionListener);

    frame.setSize(350, 200);
    frame.setVisible(true);
}

From source file:io.neocdtv.simpleplayer.ui.PlaylistTransferHandler.java

protected String exportString(JComponent c) {
    JList list = (JList) c;
    indices = list.getSelectedIndices();
    List values = list.getSelectedValuesList();

    StringBuilder buff = new StringBuilder();

    for (int i = 0; i < values.size(); i++) {
        Object val = values.get(i);
        buff.append(val == null ? "" : val.toString());
        if (i != values.size() - 1) {
            buff.append("\n");
        }/* w w w .j  av  a 2s  . c  o m*/
    }

    return buff.toString();
}

From source file:GUI.MainWindow.java

private void launchSelectedReferences(JList referencesList) {
    List selected = referencesList.getSelectedValuesList();
    Iterator it = selected.iterator();
    while (it.hasNext()) {
        Object obj = it.next();/*from   w ww .  j  ava 2s  .  c  o  m*/
        if (obj instanceof Reference) {
            try {
                Reference ref = (Reference) obj;
                this.helper.openWebpage(new URL(ref.getUrl()));
            } catch (MalformedURLException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:GUI.MainWindow.java

public void deleteReferences(JTree tree, JList list) {

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node == null) {
        return;//w ww  . ja  v a  2s  . c o  m
    }

    Object obj = node.getUserObject();
    if (!(obj instanceof Vulnerability)) {
        return;
    }

    // Get currently selected vulnerability
    Vulnerability vuln = (Vulnerability) obj;
    DefaultListModel dlm = (DefaultListModel) list.getModel();
    List selected = list.getSelectedValuesList();
    for (Object ref_obj : selected) {
        if (ref_obj instanceof Reference) {
            Reference ref = (Reference) ref_obj;
            vuln.deleteReference(ref);
            dlm.removeElement(ref_obj);
            System.out.println("Deleted Reference: " + ref);
        } else {
            System.out.println("Somehow the references list contained a non-Regerence object");
        }
    }
}

From source file:put.semantic.fcanew.ui.MainWindow.java

private void moveAttributes(int from, int to) {
    JList list = new JList[] { unusedAttributes, usedAttributes, forcedAttributes }[from];
    List selected = list.getSelectedValuesList();
    for (Object o : selected) {
        Attribute a = (Attribute) o;
        attributes.move(a, from, to);/*from  w  w w  .j  av  a 2  s .  c o m*/
    }
}