Hi all,
I've bumped into an odd problem creating a GUI in swing. As you will see in the screenshots, I have a tabbed layout. Each tab is a Jpanel. On this panel I have put a JList, containing a series of objects. My intention is to have a single column of objects in the list, and have it to scroll when the objects exceed the vertical space.
My code is this:
- private JComponent createListBox() {
-
Object[] test = {"Thingy 1","Thingy 2",...};
-
JList list = new JList(test);
-
list.setLayoutOrientation(JList.VERTICAL_WRAP);
-
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
list.setSize(385, 480);
-
list.setPreferredSize(new Dimension(385, 480));
-
-
list.setVisibleRowCount(-1);
-
list.setPreferredSize(new Dimension(385,480));
-
JScrollPane listScroller = new JScrollPane(list);
-
return listScroller;
-
}
I know it should not be VERTICAL_WRAP, do read on.
When I use VERTICAL_WRAP I get this:

It's more than one column, I agree, but atleast it works.
When I use VERTICAL (which should be the option for what I intend to do) I get this:

My JList is squashed. It appears it doesn't take the set sizes into account.
I have little experience in creating GUI's, and I haven't found a solution. I hope you can help me.
Thanks.
The layoutManger on the pannel is a FlowLayout btw.