Java tutorial
//package com.java2s; import javax.swing.JList; import javax.swing.ListModel; public class Main { public static int seachList(JList list, String match, int startIndex, boolean ingoreCase) { if (list == null || isStrEmpty(match) || list.getModel().getSize() <= 0 || startIndex < 0 || startIndex >= list.getModel().getSize()) { return -1; } ListModel model = list.getModel(); int searchCount = 0; for (; startIndex < model.getSize(); startIndex++) { if (ingoreCase) { if (model.getElementAt(startIndex).toString().toUpperCase().indexOf(match.toUpperCase()) >= 0) { return startIndex; } } else { if (model.getElementAt(startIndex).toString().indexOf(match) >= 0) { return startIndex; } } searchCount++; if (searchCount >= model.getSize()) { return -1; } if (startIndex >= model.getSize() - 1) { startIndex = -1; } } return -1; } public static boolean isStrEmpty(String str) { if (str == null) { return true; } return str.length() <= 0; } }