当前位置: 首页>>代码示例>>Java>>正文


Java JList类代码示例

本文整理汇总了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);
        }
    });
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:19,代码来源:JSList.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:FoldOptionsPanel.java

示例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();
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:24,代码来源:DeptView.java

示例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;
}
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:19,代码来源:IconListCellRenderer.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ActionMappings.java

示例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);
    }
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:20,代码来源:QueueMenuMouseListener.java

示例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();
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:22,代码来源:ProcessBrowser.java

示例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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:ListTransferHandler.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TaskPanel.java

示例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;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:22,代码来源:EndTurnDialog.java

示例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;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:PlotterPanel.java

示例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;
}
 
开发者ID:ser316asu,项目名称:SER316-Ingolstadt,代码行数:23,代码来源:StickerDialog.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:MultiDiffPanelController.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:DashboardTransferHandler.java

示例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));
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:BaseEntityWithAddDialogTool.java


注:本文中的javax.swing.JList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。