码迷,mamicode.com
首页 > 其他好文 > 详细

e779. 获得JList中的已选项

时间:2018-09-06 11:02:53      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:nta   mode   sts   OLE   first   glin   examples   value   min   

The following methods return the indices of the selected items:

    // To create a list, see e774 创建JList组件
    
    // Get the index of all the selected items
    int[] selectedIx = list.getSelectedIndices();
    
    // Get all the selected items using the indices
    for (int i=0; i<selectedIx.length; i++) {
        Object sel = list.getModel().getElementAt(selectedIx[i]);
    }
    
    // Get the index of the first selected item
    int firstSelIx = list.getSelectedIndex();
    
    // Get the index of the last selected item
    int lastSelIx = list.getMaxSelectionIndex();
    
    // Determine if the third item is selected
    int index = 2;
    boolean isSel = list.isSelectedIndex(index);
    
    // Determine if there are any selected items
    boolean anySelected = !list.isSelectionEmpty();

The following methods return the selected item objects:

    // Get the first selected item
    Object firstSel = list.getSelectedValue();
    
    // Get all selected items without using indices
    Object[] selected = list.getSelectedValues();

 

Related Examples

e779. 获得JList中的已选项

标签:nta   mode   sts   OLE   first   glin   examples   value   min   

原文地址:https://www.cnblogs.com/borter/p/9596138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!