Component alignment, Docking components – MiG InfoCom MiG Layout Quick Start Guide User Manual

Page 5

Advertising
background image

MigLayout layout = new MigLayout("insets 10");

MigLayout layout = new MigLayout("insets 0 10 10 20"); // T, L, B, R.

Component Alignment

Components that are alone in a cell can be aligned within that cell, if there is space left over. You can specify
this in the column/row constraints to get a default align for the components and/or you can specify it in the
component's constraints.

MigLayout layout = new MigLayout(
"", // Layout Constraints
"[center][right][left][c]", // Column constraints with default align
"[top][center][b]"); // Row constraints with default align

and/or when you add the components:

panel.add(comp, "align left");

Note that you can use the first letter of the alignment if you prefer.
If you have more than one component in a cell the alignment keywords will not work since the behavior
would be indeterministic. You can however accomplish the same thing by setting a gap before and/or after
the components. That gap may have a minimum size of 0 and a preferred size of a really large value to
create a "pushing" gap. There is even a keyword for this: "push". So "gapleft push" will be the same as
"align right" and work for multi-component cells as well.

Docking Components

You can dock components much like how BorderLayout in Swing works, except you aren't confined to use
only one component per side and a predefined usage of the corners. The docking components is always
placed outside the normal layout. You can mix grid and docking components in the same layout.

panel.add(comp1)
panel.add(comp2)
panel.add(comp3, "wrap") // Wrap to next row
panel.add(comp4)
panel.add(comp1N, "dock north")
panel.add(comp2W, "dock west")
panel.add(comp3S, "dock south")
panel.add(comp4E, "east")

// "dock" keyword are actually optional

comp1N

comp2W

comp1

comp2

comp3

comp4

comp4E

comp3S

© 2009 MiG InfoCom AB

Advertising