Ricerca…


Modifica gli elementi selezionati in una JList

Dato un JList come

JList myList = new JList(items);

gli elementi selezionati nell'elenco possono essere modificati tramite ListSelectionModel di JList :

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

In alternativa, JList fornisce anche alcuni metodi utili per manipolare direttamente gli indici selezionati:

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
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow