Linked Questions

Popular Questions

JScrollPane not showing up with JList

Asked by At

I am trying to get a scroll pane in a JList in order to scroll through the list. The scroll pane isn't showing up however. I tried multiple fixes and it didn't work, can someone tell me what I am doing wrong? This is a snippet of my code that the scroll pane is in.

private void setUpVariables() {
    contacts = new ArrayList<Contact>();

    list_contacts = new JList(contacts.toArray());
    list_contacts.setBounds(0, 0, 200, 400);

    scroller_contacts = new JScrollPane(list_contacts);
    scroller_contacts.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);

 scroller_contacts.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);

    panel.add(list_contacts);
    panel.add(scroller_contacts);
    add(panel);
}

When I use that code, my JList shows up perfectly normal and I can add items to it and it will function. The scroll pane just never shows up, even when the JList goes out of bounds.

Related Questions