0

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
}
3
  • You want to use a JListBox and set the listModel to your data. Commented Jul 31, 2013 at 14:58
  • What is Reader? Where do columns come into this; you seem to want the different strings put into their own rows. Commented Jul 31, 2013 at 15:03
  • Sorry, my bad. No more "extends Reader" now. Hope you can help now Commented Jul 31, 2013 at 15:13

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@olicvermuchai Not a problem. I would appreciate if the answer helped you, can you upvote or accept the answer and close the question. Thanks
I will a bit later. can't upvote you right now: just joined StackOverflow and my points aren't high enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.