Code example for JList

Methods: setCellRenderersetSelectionModesetVisibleRowCount

0
        GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
        GraphModel model = graphController.getModel();
        Graph graph = model.getGraph();
        listNode = Arrays.asList(graph.getNodes().toArray());
        Collections.sort(listNode, new NodeByLabelComparator());
        list = new JList(listNode.toArray());
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(10);
        list.setCellRenderer(new NodeListRenderer());
        JScrollPane listScroller = new JScrollPane(list);        
        this.add(listScroller);
    } 
 
    public void setSelected(int index) {
        list.setSelectedIndex(index);
    } 
 
    public Node getSelected() { 
        return (Node) list.getSelectedValue();
    } 
Connect your IDE to all the code out there  Get Codota for Java