首页 > 其他 > 详细

e779. 获得JList中的已选项

时间:2018-09-06 10:03:42      阅读:138      评论:0      收藏:0      [点我收藏+]

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中的已选项

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!