Java examples for Swing:JList
set Selection to JList
//package com.java2s; import javax.swing.JList; public class Main { public static void setSelection(JList list, Object element) { for (int i = 0; i < list.getModel().getSize(); i++) { Object value = (Object) list.getModel().getElementAt(i); if (value == element) { list.setSelectedIndex(i); list.scrollRectToVisible(list.getCellBounds(i, i)); return; }/*from w w w .ja va 2 s .c om*/ } } }