uDig

«  Guide To EMF   ::   Contents   ::   IAdaptable  »

Guide to MigLayout

MigLayout has been added as a core dependency for uDig; giving us a consistent layout manager that is a little bit shorter on ceremony then the traditional SWT FormLayout. It is also aware of platform differences and can sort out the correct “Gap” between fields and the correct button order in order to fit in with other windows, linux, mac osx applications.

Related:

Draw a Diagram

Always start with a plan, on paper or a whiteboard, or your will drive yourself batty!

_images/plan.jpg

Draw a grid onto your plan; or arrows or whatever else you need to sort out what the layout settings will be.

_images/plan_grid-1.jpg

And then turn it into code.

shell.setLayout( new MigLayout("","[right]10[left,grow][min!][min!]","30"));

Label label = new Label(shell, SWT.SHADOW_IN);
label.setText("Country:");

name = new Text(shell, SWT.SHADOW_IN | SWT.BORDER);
name.setLayoutData("span 3, growx, wrap");
name.addKeyListener(this);
...

Suggestions for the above example:

  1. 10 represents 10 pixels (or “10px”) is not a very good idea as display resolutions are starting to change between computers.
    • Consider “10lp” (for 10 logical pixels) works better and will adjust for the current resolution
    • Consider “related” to indicate the two are related; the actual gap here will depend on windows,linux, osx
    • Other gaps to consider: “unrelated”, and “paragraph”

«  Guide To EMF   ::   Contents   ::   IAdaptable  »