Java JList Select setSelectedList(JList list, Object selected)

Here you can find the source of setSelectedList(JList list, Object selected)

Description

set Selected List

License

LGPL

Parameter

Parameter Description
list JList
selected Object

Declaration

public static void setSelectedList(JList list, Object selected) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.swing.*;

public class Main {
    /**//  ww  w  .j a v a 2s .c om
     *
     * @param list JList
     * @param selected Object
     */
    public static void setSelectedList(JList list, Object selected) {
        if (list == null) {
            return;
        }
        if (list.getModel().getSize() == 0) {
            return;
        }
        if (selected == null) {
            list.setSelectedIndex(0);
        } else {
            list.setSelectedValue(selected, true);
        }
    }
}

Related

  1. selectRow(int row, ListSelectionModel model)
  2. selectStringInList(String string, JList list)
  3. setJListSelection(List selection, JList list)
  4. setLeadAnchorWithoutSelection(ListSelectionModel model, int lead, int anchor)
  5. setSelectedItems(JList list, List selected)
  6. setSelectedListIndices(final JList list, final List indices)
  7. setSelectedValue(JList list, Object value)
  8. setSelectedValues(JList jList, Object[] values)
  9. setSelection(JList list, Object element)