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

📄 e780. setting the selected items in a jlist component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
List selection events are fired when the following methods are used to change the set of selected items (see e774 Creating a JList Component). 
    // Create a list and get the model
    String[] items = {"A", "B", "C", "D"};
    JList list = new JList(items);
    
    // Select the second item
    int start = 1;
    int end = 1;
    list.setSelectionInterval(start, end);       // B
    
    // Select the first 3 items
    start = 0;
    end = 2;
    list.setSelectionInterval(start, end);       // A, B, C
    
    // Select all the items
    start = 0;
    end = list.getModel().getSize()-1;
    if (end >= 0) {
        list.setSelectionInterval(start, end);   // A, B, C, D
    }
    
    // Clear all selections
    list.clearSelection();
    
    // Select the first item
    start = 0;
    end = 0;
    list.setSelectionInterval(start, end);       // A
    
    // Add another selection - the third item
    start = 2;
    end = 2;
    list.addSelectionInterval(start, end);       // A, C
    
    // Deselect the first item
    start = 0;
    end = 0;
    list.removeSelectionInterval(start, end);    // C
    
    // Select a single item
    boolean scrollIntoView = true;
    list.setSelectedValue("B", scrollIntoView);  // B

⌨️ 快捷键说明

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