Code example for JList

Methods: getSelectedValuessetSelectedIndicessetSelectionMode

0
        demoModel.setSelectedItem("Quick");
        assertEquals("Quick", demoList.getSelectedValue());
    } 
 
    public void testMultiList() { 
        demoMultiselectList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        assertEquals(0, demoMultiselectList.getSelectedValues().length);
        demoMultiselectList.setSelectedIndices(new int[] { 1, 2, 4 });
        List<String> items = demoModel.getMultiSelectedItems();
        assertEquals(3, items.size());
        assertEquals("bravo", items.get(0));
        assertEquals("charlie", items.get(1));
        assertEquals("echo", items.get(2));
        demoModel.setMultiSelectedItems(ImmutableList.of("bravo", "delta"));
        Object[] selectedValues = demoMultiselectList.getSelectedValues();
        assertEquals("bravo", selectedValues[0]);
        assertEquals("delta", selectedValues[1]);
    } 
} 
 
Experience pair programming with AI  Get Codota for Java