Java examples for Swing:JList
set Selected List item on JList
//package com.java2s; import javax.swing.*; public class Main { /**/*from w w w. j ava 2s.c o m*/ * * @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); } } }