Oliver Muchai
Oliver Muchai

Reputation: 279

How to display an ArrayList in a JPanel

How can I get a JList to show in a JPenel. For example I'd like to have the following groups of items displayed in a JPanel, with each group showing on it's own column, with a new group being dropped into a new line, like how Google lists search results.

For example:

import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;


public class ReaderImpl {
    JPanel paneTo = new JPanel();

    List<String> text() {
        List<String> lovely = new ArrayList<String>(4);
            lovely.add("Tall, Short, Average");         // line 1
            lovely.add("mangoes, apples, Bananas");     // line 2
            lovely.add("12, 33");  
        return lovely;
    }

    // How do I add the lovely ArrayList to paneTo
}

Upvotes: 0

Views: 1671

Answers (1)

JNL
JNL

Reputation: 4703

A JList renderer can draw a checkbox, but JList does not support a cell editor. Instead, consider a one-column JTable.

Check out this link here.

Hope that helps.

Upvotes: 1

Related Questions