Example usage for javax.swing JList JList

List of usage examples for javax.swing JList JList

Introduction

In this page you can find the example usage for javax.swing JList JList.

Prototype

public JList(final Vector<? extends E> listData) 

Source Link

Document

Constructs a JList that displays the elements in the specified Vector.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    boolean scrollIntoView = true;
    list.setSelectedValue("B", scrollIntoView);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    int start = 2;
    int end = 2;//from ww  w .  j  a  va2  s. c om
    list.addSelectionInterval(start, end);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    int start = 0;
    int end = 0;//from   w  w  w .  j a  v a  2  s. c o  m
    list.removeSelectionInterval(start, end);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    String protoCellValue = "My Sample Item Value";
    list.setPrototypeCellValue(protoCellValue);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    int start = 0;
    int end = 0;//from   ww w .ja v a 2s . co m
    list.setSelectionInterval(start, end);
}

From source file:Main.java

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;//  w  w w. jav a 2  s . c o  m
    list.setSelectionInterval(start, end);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    int itemIx = list.getFirstVisibleIndex();
    if (itemIx < 0) {
        // List is either not visible or there are no items
    }//from   w w  w  .  ja  v  a 2s  .  c  om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    // Get the first selected item
    Object firstSel = list.getSelectedValue();

    // Get all selected items without using indices
    Object[] selected = list.getSelectedValues();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    int start = 0;
    int end = list.getModel().getSize() - 1;
    if (end >= 0) {
        list.setSelectionInterval(start, end);
    }/*from ww w  .j a  v a2  s.co  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    String prefix = "b";

    int start = 0;

    int itemIx = list.getNextMatch(prefix, start, javax.swing.text.Position.Bias.Forward);
}