サーチ…


JListで選択した要素を変更する

JListようなもの

JList myList = new JList(items);

リスト内の選択された項目は、 JList ListSelectionModelによって変更できます。

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

JListは、選択されたインデックスを直接操作するための便利なメソッドも提供します。

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
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow