Java Swing Tutorial - Java JList.isSelectedIndex(int index)








Syntax

JList.isSelectedIndex(int index) has the following syntax.

public boolean isSelectedIndex(int index)

Example

In the following code shows how to use JList.isSelectedIndex(int index) method.

//from  w ww .  j  a v a  2  s.  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);

    int index = 2;
    boolean isSel = list.isSelectedIndex(index);
  }
}