本文整理汇总了Java中javax.swing.JList类的典型用法代码示例。如果您正苦于以下问题:Java JList类的具体用法?Java JList怎么用?Java JList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JList类属于javax.swing包,在下文中一共展示了JList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: FoldOptionsPanel
import javax.swing.JList; //导入依赖的package包/类
/**
* Creates new form FoldOptionsPanel
*/
public FoldOptionsPanel(FoldOptionsController ctrl) {
this.ctrl = ctrl;
initComponents();
langSelect.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof String[]) {
value = ((String[])value)[1];
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates.
}
});
langSelect.addActionListener(this);
contentPreview.addActionListener(this);
foldedSummary.addActionListener(this);
// preferences should be set as a reaction to index selection
}
示例3: DeptView
import javax.swing.JList; //导入依赖的package包/类
public DeptView(Controller controller) {
this.controller = controller;
frame = new JFrame();
namePanel = new JPanel(new GridLayout(1, 2, 0, 0));
managerPanel = new JPanel(new GridLayout(1, 2, 66, 0));
employeePanel = new JPanel(new GridLayout(1, 2, 30, 0));
subDeptPanel = new JPanel(new GridLayout(1, 2, 20, 0));
salaryPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
buttonPanel = new JPanel(new GridLayout(1, 3, 20, 0));
subDeptLabel = new JLabel();
salaryLabel = new JLabel();
cutButton = new JButton();
saveButton = new JButton();
okButton = new JButton();
cancelButton = new JButton();
nameField = new JTextField();
managerButton = new JButton();
employeeListModel = new DefaultListModel();
subDeptListModel = new DefaultListModel();
employeeList = new JList(employeeListModel);
subDeptList = new JList(subDeptListModel);
init();
}
示例4: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value != null) {
setText(value.toString());
ImageIcon imageIcon = new javax.swing.ImageIcon(getClass().getResource("/app/resources/" + icon_resource));
setIcon(imageIcon);
}
setForeground(list.getForeground());
setBackground(list.getBackground());
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
return this;
}
示例5: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value,
int arg2, boolean arg3,
boolean arg4) {
Component supers = super.getListCellRendererComponent(list, value, arg2, arg3, arg4);
if (supers instanceof JLabel && value instanceof MappingWrapper) {
MappingWrapper wr = (MappingWrapper)value;
JLabel lbl = (JLabel)supers;
if (wr.isUserDefined()) {
lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
} else {
lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
}
}
return supers;
}
示例6: mouseClicked
import javax.swing.JList; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
if (!(e.getSource() instanceof JList)) {
return;
}
queueList = (JList) e.getSource();
queueListModel = (DefaultListModel) queueList.getModel();
queueList.requestFocus();
int nx = e.getX();
if (nx > 500) {
nx = nx - popup.getSize().width;
}
popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
}
}
示例7: buildList
import javax.swing.JList; //导入依赖的package包/类
/**
* Creates the process list
*
* @return JComponent
*/
private JComponent buildList() {
list = new JList<>();
list.setCellRenderer(new CellRenderer(list.getCellRenderer()));
list.setTransferHandler(new ProcessTransferHandler());
list.setDragEnabled(true);
list.setDropMode(DropMode.ON_OR_INSERT);
list.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() % 2 == 0) {
ProcessInformationPane.showDialog(list.getSelectedValue());
}
}
});
return ScrollFactory.pane(list).create();
}
示例8: cleanup
import javax.swing.JList; //导入依赖的package包/类
protected void cleanup(JComponent c, boolean remove) {
if (remove && indices != null) {
JList source = (JList) c;
DefaultListModel model = (DefaultListModel) source.getModel();
// If we are moving items around in the same list, we
// need to adjust the indices accordingly, since those
// after the insertion point have moved.
if (addCount > 0) {
for (int i = 0; i < indices.length; i++) {
if (indices[i] > addIndex) {
indices[i] += addCount;
}
}
}
for (int i = indices.length - 1; i >= 0; i--) {
model.remove(indices[i]);
}
}
indices = null;
addCount = 0;
addIndex = -1;
}
示例9: enableComponents
import javax.swing.JList; //导入依赖的package包/类
private void enableComponents (Component comp, boolean enable) {
if (comp instanceof Container) {
for (Component subComp : ((Container) comp).getComponents()) {
enableComponents(subComp, enable);
}
}
if ((comp instanceof JComboBox)
|| ((comp instanceof JTextComponent) && ((JTextComponent) comp).isEditable())
|| (comp instanceof AbstractButton) || (comp instanceof JList)) {
if (enable) {
Boolean b = enableMap.get(comp);
if (b != null) {
comp.setEnabled(b);
}
} else {
enableMap.put(comp, comp.isEnabled());
comp.setEnabled(false);
}
}
}
示例10: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(JList<? extends UnitWrapper> list,
UnitWrapper value,
int index,
boolean isSelected,
boolean cellHasFocus) {
imageLabel.setIcon(new ImageIcon(
getImageLibrary().getSmallerUnitImage(value.unit)));
nameLabel.setText(value.name);
locationLabel.setText(value.location);
JPanel panel = (isSelected) ? selectedPanel : itemPanel;
panel.removeAll();
panel.add(imageLabel, "center, width 40!, height 40!");
panel.add(nameLabel, "split 2, flowy");
panel.add(locationLabel);
return panel;
}
示例11: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
String s = value.toString();
setText(s);
Icon icon = plotter.getIcon(index);
if (icon != null) {
setIcon(icon);
}
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
setOpaque(true);
return this;
}
示例12: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
/*
* if (isSelected) { setBackground(list.getSelectionBackground());
* setForeground(list.getSelectionForeground());
*/
if(index==7){
this.setForeground(Color.WHITE);
}
else setForeground(list.getForeground());
if ((index > -1) && (index < colors.length))
setBackground(colors[index]);
else
setBackground(list.getBackground());
//}
setText(value.toString());
return this;
}
示例13: getListCellRendererComponent
import javax.swing.JList; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String tooltip = null;
if (value instanceof Revision) {
Revision rev = (Revision) value;
value = rev.toString(true);
tooltip = rev.getFullMessage();
if (tooltip != null) {
tooltip = tooltip.replace("\r\n", "\n").replace("\n", "<br>"); //NOI18N
StringBuilder sb = new StringBuilder("<html><p>"); //NOI18N
sb.append(tooltip).append("</p></html>"); //NOI18N
tooltip = sb.toString();
}
} else if (value instanceof String) {
value = "<html><i>" + value + "</i></html>"; //NOI18N
tooltip = Bundle.MSG_Revision_Select_Tooltip();
}
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (comp instanceof JComponent) {
((JComponent) comp).setToolTipText(tooltip);
}
return comp;
}
示例14: createTransferable
import javax.swing.JList; //导入依赖的package包/类
@Override
protected Transferable createTransferable(JComponent c) {
if (c instanceof JList) {
JList list = (JList) c;
Object[] values = list.getSelectedValues();
if (values == null || values.length == 0) {
return null;
}
List<TaskNode> nodes = new ArrayList<TaskNode>(values.length);
for (int i = 0; i < values.length; i++) {
Object val = values[i];
if (val instanceof TaskNode) {
nodes.add((TaskNode) val);
} else {
return null;
}
}
return new DashboardTransferable(nodes.toArray(new TaskNode[nodes.size()]));
}
return null;
}
示例15: PluginDialog
import javax.swing.JList; //导入依赖的package包/类
public PluginDialog()
{
listModel = new DefaultListModel<>();
list = new JList<>();
list.setModel(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
for( String name : plugins.keySet() )
{
listModel.addElement(name);
}
setLayout(new BorderLayout());
add(new JScrollPane(list));
}