本文整理汇总了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);
}
});
}
示例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;
}
示例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;
}
示例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);
}