I'm new to MigLayout. I'm attempting to create a layout similar to this:
There is a row of equally spaced buttons, followed by a row with a list that spans all of the columns and grows to fill the available vertical space, followed by a final row with a few more controls.
I can get the first two rows without much difficulty.
However, when I add the content of the final row, MigLayout (rightfully) attempts to preserve the columns of the first two rows. I'm left with something like this:
The label and spinner in the last row extend the width of the columns and I'm left with uneven gaps in the top row.
Is there some way to tell MigLayout that I want to forget about the rows/columns established thus far and to "start fresh," or is the solution here to create a nested layout?
Here's a full example panel.
public class TestPanel extends JPanel {
JButton button1 = new JButton("Button 1");
JButton button2 = new JButton("Button 2");
JButton button3 = new JButton("Button 3");
JButton button4 = new JButton("Button 4");
JButton button5 = new JButton("Button 5");
JList list = new JList(new String[]{"some", "fake", "data"});
JLabel label = new JLabel("this is my long label");
JSpinner spinner = new JSpinner();
JCheckBox checkbox = new JCheckBox("Check me");
public TestPanel() {
initComponents();
}
private void initComponents() {
setLayout(new MigLayout());
add(button1);
add(button2);
add(button3);
add(button4);
add(button5, "wrap");
add(list, "span, growx, growy, wrap");
// without these 3 lines, the row of buttons are equally spaced
// adding the long label extends the width of the first column
add(label);
add(spinner);
add(checkbox, "span, align right");
}
}