Component Orientation, TOP to BOTTOM.

I am using Gridlayout with 30 rows and 1 column. Thinking of using 15 rows and 2 columns instead but I want to list the first 15 to the left and the last 15 to the right

1 2
3 4

is not what I want

instead

1 16
2 17
3 18
4 19
5 20
6 21
7 22
8 23
9 24
10 25
11 26
12 27
13 28
14 29
15 30

Any way to do it?

put your components in an array and feed the array in the way the GridLayout expects, and AFAIK you can’t change the ordering of components


JPanel mainPanel = new JPanel(new GridLayout(1, 2));
JPanel leftPanel = new JPanel(new GridLayout(15, 1));
JPanel rightPanel = new JPanel(new GridLayout(15, 1));

mainPanel.add(leftPanel);
mainPanel.add(rightPanel);

Don’t forget that you can layer layout managers. Anytime you are creating a complex layout and are unsure about how to proceed, just make a drawing of the layout and use vertical and horizontal lines to cut the diagram into layout managers.

Indeed, until we get a decent layout manager, that doesn’t require any tools.

If the Components are the same size and there are the same number of Components in each column, you could probably just make a horizontal box of 2 vertical boxes.

But to use GridLayout, you can just add the components in a different order like someone already said.

You can always use setLayout(null) and setBounds(x,y,w,h) on all Components. It can be a pain to do, but has highest precision and flexibility in the end. Using a visual editor might be an idea.

-JAW

Learn to use LayoutManagers effectively and you will be happier for it.

There’s an alternative to null layouts at http://www.swingwiki.org/workaround:fixed_position_layout . I wrote my own slightly different version that uses Rectangles.