當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。