There are several ways to do this (we could use insets instead of gaptop/bottom for example). Here is a simple example:
JPanel p = new JPanel();
p.setLayout(new MigLayout("fill"));
p.add(new JLabel("1"), "top, gaptop 20px, center, wrap");
p.add(new JLabel("2"), "bottom, gapbottom 20px, center");
The above example uses top
and bottom
to position the labels at the top and bottom of the panel. A more realistic example, where we have content between these labels, may be something like this:
JPanel p = new JPanel();
p.setLayout(new MigLayout("debug, fill, insets 20 0 20 0", "", "[][grow][]"));
p.add(new JLabel("Top"), "center, wrap");
p.add(new JLabel("Center"), "center, grow, wrap");
p.add(new JLabel("Bottom"), "center");
This example uses insets for the desired 20px gap top and bottom, this way the 20px gap isnt added to the labels row.