⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e779. getting the selected items in a jlist component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
The following methods return the indices of the selected items: 
    // To create a list, see e774 Creating a JList Component
    
    // 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();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -