當前位置: 首頁>>代碼示例>>Java>>正文


Java JList.setSelectionModel方法代碼示例

本文整理匯總了Java中javax.swing.JList.setSelectionModel方法的典型用法代碼示例。如果您正苦於以下問題:Java JList.setSelectionModel方法的具體用法?Java JList.setSelectionModel怎麽用?Java JList.setSelectionModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JList的用法示例。


在下文中一共展示了JList.setSelectionModel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ListPanel

import javax.swing.JList; //導入方法依賴的package包/類
public ListPanel(FilterModel fltrmodel, Function<T, String> mapper) {
    setLayout(new java.awt.BorderLayout());
    JScrollPane sp = new javax.swing.JScrollPane();
    list = new JList();
    list.setModel(fltrmodel);
    list.setCellRenderer(new CheckBoxListRenderer(mapper));
    sp.setViewportView(list);
    add(sp, BorderLayout.CENTER);
    list.setSelectionModel(new MultiSelectionModel(this::onSelect));
    list.addKeyListener(onDelete());
    list.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ctrl A"), "SelectAll");
    list.getActionMap().put("SelectAll", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            list.setSelectionInterval(0, list.getModel().getSize() - 1);
        }
    });
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:19,代碼來源:JSList.java

示例2: createSyntaxPanel

import javax.swing.JList; //導入方法依賴的package包/類
private JComponent createSyntaxPanel(Logic logic) {
    final JList<String> list = new JList<>();
    DefaultListModel<String> model = new DefaultListModel<>();
    Map<String,String> docMap = FormulaParser.getDocMap(logic);
    for (Map.Entry<String,String> entry : docMap.entrySet()) {
        model.addElement(entry.getKey());
    }
    list.setModel(model);
    list.setCellRenderer(new MyCellRenderer(docMap));
    list.addMouseListener(new DismissDelayer(list));
    list.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            super.setSelectionInterval(-1, -1);
        }
    });
    JPanel result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
    result.add(new JLabel("<html><b>Syntax:"), BorderLayout.NORTH);
    result.add(new JScrollPane(list), BorderLayout.CENTER);
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:23,代碼來源:HelpFactory.java

示例3: createSyntaxPanel

import javax.swing.JList; //導入方法依賴的package包/類
private JComponent createSyntaxPanel() {
    final JList<String> list = new JList<>();
    DefaultListModel<String> model = new DefaultListModel<>();
    for (Map.Entry<String,String> entry : this.docMap.entrySet()) {
        model.addElement(entry.getKey());
    }
    list.setModel(model);
    list.setCellRenderer(new MyCellRenderer(this.docMap));
    list.addMouseListener(new DismissDelayer(list));
    list.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            super.setSelectionInterval(-1, -1);
        }
    });
    JPanel result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
    result.add(new JLabel("<html><b>Syntax:"), BorderLayout.NORTH);
    result.add(new JScrollPane(list), BorderLayout.CENTER);
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:22,代碼來源:StringDialog.java

示例4: initUI

import javax.swing.JList; //導入方法依賴的package包/類
private void initUI() {
    categoriesModel = new CategoriesListModel();
    categoriesSelection = new CategoriesSelectionModel();
    
    scrollIncrement = new JCheckBox("XXX").getPreferredSize().height; // NOI18N
    
    JList<ProfilerOptionsPanel> categoriesList = new JList(categoriesModel) {
        public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            dim.width = Math.max(dim.width + 20, 140);
            return dim;
        }
    };
    categoriesList.setVisibleRowCount(0);
    categoriesList.setSelectionModel(categoriesSelection);
    categoriesList.setCellRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            String panelName = " " + ((ProfilerOptionsPanel)value).getDisplayName() + " "; // NOI18N
            return super.getListCellRendererComponent(list, panelName, index, isSelected, cellHasFocus);
        }
    });
    
    JScrollPane categoriesScroll = new JScrollPane(categoriesList);
    
    JLabel categoriesLabel = new JLabel();
    categoriesLabel.setHorizontalAlignment(JLabel.LEADING);
    Mnemonics.setLocalizedText(categoriesLabel, Bundle.ProfilerOptionsContainer_Categories());
    categoriesLabel.setLabelFor(categoriesList);
    int labelOffset = 6;
    
    JPanel categoriesPanel = new JPanel(new BorderLayout(0, labelOffset));
    categoriesPanel.add(categoriesLabel, BorderLayout.NORTH);
    categoriesPanel.add(categoriesScroll, BorderLayout.CENTER);
    
    content = new JPanel(new BorderLayout());
    content.setBorder(BorderFactory.createEmptyBorder(categoriesLabel.getPreferredSize().height + labelOffset, 11, 0, 0));
    content.setMinimumSize(new Dimension(0, 0));
    content.setPreferredSize(new Dimension(0, 0));
    
    setLayout(new BorderLayout());
    add(categoriesPanel, BorderLayout.WEST);
    add(content, BorderLayout.CENTER);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:44,代碼來源:ProfilerOptionsContainer.java


注:本文中的javax.swing.JList.setSelectionModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。