zoukankan      html  css  js  c++  java
  • e780. 设置JList中的已选项

    List selection events are fired when the following methods are used to change the set of selected items (see e774 创建JList组件).

        // 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
    
    Related Examples
  • 相关阅读:
    Java实战项目收集
    Drebin数据集
    网络“法官”
    沉醉
    孔方兄
    《Qt 5.9 C++开发指南》例程源码
    《论语》中那些耳熟能详的词汇
    破祟
    Qt使用UI编辑器添加的控件Icon运行时不显示
    Ubuntu格式化SD卡
  • 原文地址:https://www.cnblogs.com/borter/p/9596142.html
Copyright © 2011-2022 走看看