While playing a bit to demonstrate how to easily fulfil a layout requirment with MigLayout, I was surprised by the outcome of:
MigLayout layout = new MigLayout("wrap 3, debug");
JComponent content = new JPanel(layout);
content.add(new JLabel("First:"));
content.add(new JScrollPane(new JTextArea(10, 20)), "skip, spany");
content.add(new JLabel("Second"));
content.add(new JTextField(10));
content.add(new JLabel("third"));
content.add(new JTextField(10));
//content.add(new JLabel());
The layout idea is simple enough:
- three columns
- last column spanning all rows
- first two columns a bunch of label/component pairs
The unexpected is that the last row of the first two columns takes all the available vertical space which leads to positioning the last pair in its middle (top align is not an option, as they must be baseline aligned to each other)
uncommenting the last line above (adding a virtually invisible dummy) shows the expected layout, but a hack which shouldn't go into production code
The question is: how to achieve the expected layout without hacking?