0%

MigLayout实践笔记

MigLayout whitepaper

构造函数

1
2
3
//布局约束  列约束  行约束
//也有其它构造函数,默认对应参数为空字符串
public MigLayout(String layoutConstraints, String colConstraints, String rowConstraints)

layoutConstraints 布局约束

  1. hidemode

    Sets the hide mode for the component. If the hide mode has been specified in the This hide mode can be overridden by the component constraint. The hide mode specified how the layout manager should handle a component that isn’t visible. The modes are:

    0 - Default. Means that invisible components will be handled exactly as if they were visible.

    1 - The size of the component (if invisible) will be set to 0, 0.

    2 - The size of the component (if invisible) will be set to 0, 0 and the gaps will also be set to 0 around it.

    3 - Invisible components will not participate in the layout at all and it will for instance not take up a grid cell.

    Example: “hidemode 1”

  2. wrap+数字

    指定第几个组件后进行换行,如:wrap 2表示第二个组件后换行

  3. insets+数字

    指定与边界的距离,如:insets 10表示四边均为10,insets 1 2 3 4表示顶部,左侧,下部,右侧的距离

colConstraints 列约束 和 rowConstraints 行约束

1
MigLayout layout = new MigLayout("fillx", "[right]rel[grow,fill]", "[]10[]");

如上

  1. grow

    y/x方向按上一级宽度进行延伸.注意如果此处不添加grow,那么在添加组件时使用growygrowx将无效

  2. 数字+!

    表面该单元高度/宽度固定为数字大小.如:40!

  3. 数字:数字:数字

    分别表示: 最小距离:最佳距离:最大距离.如10:30:40,也可以::40,表示最大40,其它无限制,同理:10::,:30:

  4. top/bottom/center

    垂直方向对齐方式

  5. center/right/left

    水平方向对齐方式

添加组件

1
panel.add(component,"");

第二个字符串参数可使用以下约束:

  1. growx/growy

    在水平/垂直方向延伸.前提布局约束有已开启延伸.如panel.add(button,"growx")

  2. span

    span占用本行所有单元格,span 2占用横向两个单元格,span 2 3占用横向2个单元格和纵向3个单元格

  3. wrap

    添加本组件后进行换行

  4. gapleft/gapright/gaptop/gapbottom

    指定四周的间隔

  5. split

    split 2将该单元格分成两个单元格

  6. w 数字:数字:数字

    指定宽度属性,如 w 10:20:30,w 30!,w ::30

  7. h 数字:数字:数字

    指定高度属性,如 h 10:20:30,h 30!,h ::30

您的支持是对我最大的动力 (●'◡'●)