Sök…


Ändra de markerade elementen i en JList

Med tanke på en JList som

JList myList = new JList(items);

de valda objekten i listan kan ändras genom ListSelectionModel JList :

ListSelectionModel sm = myList.getSelectionModel();  
sm.clearSelection();                      // clears the selection
sm.setSelectionInterval(index, index);    // Sets a selection interval
                                          // (single element, in this case)

Alternativt JList också några praktiska metoder för att direkt manipulera de valda indexen:

myList.setSelectionIndex(index);            // sets one selected index
                                            // could be used to define the Default Selection

myList.setSelectedIndices(arrayOfIndexes);  // sets all indexes contained in
                                            // the array as selected


Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow