API Creation of Constraints
Shown above is the String creation of the constraints. They are used because they are short to type and
easy to read. From v2.0 of MiG Layout it is also possible to create the constraints with API calls. The API is
mapped directly to the same constraints as the string version. There is JavaDoc for the API calls but the
White Paper and Cheat Sheet is still the best and most complete source of information regarding the
different constraints. Here is an example of the usage of API constraints:
MigLayout layout = new MigLayout(
new LC().wrapAfter(3), // Layout Constraints
new AX().grow(1,3,4).size("10px",1,2), // Column constraints
new AX().noGrid(1,4)); // Row constraints
panel.add(comp, new CC().grow().width("20px")) // Component constraint
Further Reading
This document has only scratched the surface of what's possible with MiG Layout, yet it is the only thing that
is needed to make beautiful and consistent layouts. Below is a list of things that is also supported by MiG
Layout. For information how to use these features go to www.migcomponents.com and press the MiG
Layout link. There you will find Cheat Sheets for the constraints and a White Paper that explains how the
layout manager works in more detail.
More features that are supported in MiG Layout are:
● The use of many different units. E.g. mm, cm, %, inch, dots, logical pixels and screen
percentage. This include the use of relative keywords like "related", "unrelated" and
"paragraph" that will follow the design guides for the different platforms.
● Grouping columns/rows/components by size to they will be the same width and/or height.
● Free positioning using absolute coordinates. Edges can be linked to any other edge including other
components and the containers bounds.
● Full support for left-to-right and bottom-to-top layouts.
● Specify how hidden (not visible) components should behave.
● Button ordering and sizing depending on platform. For instance "OK" and "Cancel" will be of different
size and order on Windows and Mac OS X. This is handled automatically by MiG Layout.
● Last stage padding of size and position of any component.
● Customization of almost any aspect of the layout engine. It is for instance possible to add new units,
to specify gaps depending on component types and change all default values.
● Tagging components with "external" so that they aren't touched by MiG Layout and thus it is
possible to set their bounds manually, yet you can link to them.
● All constraints are JavaBeans and implements Serializable so they are 100% compatible with
persistence. UnitValue and BoundSize have custom PersistenceDelegates.
● IDEUtil is a class to help integration on MiG Layout in any IDE. It can produce the source code for
any constraint, both as API and String constraints.
● Much, much more..
© 2009 MiG InfoCom AB