4

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)

enter image description here

uncommenting the last line above (adding a virtually invisible dummy) shows the expected layout, but a hack which shouldn't go into production code

enter image description here

The question is: how to achieve the expected layout without hacking?

Community
  • 1
  • 1
kleopatra
  • 51,061
  • 28
  • 99
  • 211

1 Answers1

4

might be a bug:

a less hacky way to workaround (applicable if number of rows is known at creation time of the form) is to explicitly define the row constraints

MigLayout layout = new MigLayout("wrap 3, debug", "", "[][][][]");

that is define one row more than actually needed for the components at the side of the spanning component

kleopatra
  • 51,061
  • 28
  • 99
  • 211