Java JList .setSelectionInterval (int anchor, int lead)
Syntax
JList.setSelectionInterval(int anchor, int lead) has the following syntax.
public void setSelectionInterval(int anchor, int lead)
Example
In the following code shows how to use JList.setSelectionInterval(int anchor, int lead) method.
/*from w w w. j av a 2s . c o m*/
import javax.swing.JList;
public class Main {
public static void main(String[] argv) throws Exception {
String[] items = { "A", "B", "C", "D" };
JList list = new JList(items);
// Select the second item
int start = 1;
int end = 1;
list.setSelectionInterval(start, end);
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »