1. Introduction

MigLayout is a very powerful layout manager for Swing, JavaFX and SWT. This plugins enables the usage of toolkit specific versions of MigLayout.

Griffon version: 2.12.0

2. Configuration

The plugin delivers artifacts for both Swing and JavaFX. It also contains Groovy enhancements that can be used in combination with the respective UI toolkit DSL (SwingBuilder and GroovyFX).

2.1. Gradle

You have two options for configuring this plugin: automatic and manual.

2.1.1. Automatic

As long as the project has the org.codehaus.griffon.griffon plugin applied to it you may include the following snippet in build.gradle

dependencies {
    griffon 'org.codehaus.griffon.plugins:griffon-miglayout-plugin:2.0.0'
}

The griffon plugin will take care of the rest given its configuration.

2.1.2. Manual

You will need to configure any of the following blocks depending on your setup

Java + Swing
dependencies {
    compile 'com.miglayout:miglayout-swing:5.0'
}
Java + JavaFX
dependencies {
    compile 'org.codehaus.griffon.plugins:griffon-miglayout-javafx:2.0.0'
}
Groovy + Swing
dependencies {
    compile 'org.codehaus.griffon.plugins:griffon-miglayout-swing-groovy:2.0.0'
}
Groovy + JavaFX
dependencies {
    compile 'org.codehaus.griffon.plugins:griffon-miglayout-javafx-groovy:2.0.0'
}

2.2. Maven

First configure the griffon-miglayout-plugin BOM in your POM file, by placing the following snippet before the <build> element

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.griffon.plugins</groupId>
            <artifactId>griffon-miglayout-plugin</artifactId>
            <version>2.0.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Next configure dependencies as required by your particular setup

Java + Swing
<dependency>
    <groupId>com.miglayout</groupId>
    <artifactId>miglayout-swing</artifactId>
</dependency>
Java + JavaFX
<dependency>
    <groupId>org.codehaus.griffon.plugins</groupId>
    <artifactId>griffon-miglayout-javafx</artifactId>
</dependency>
Groovy + Swing
<dependency>
    <groupId>org.codehaus.griffon.plugins</groupId>
    <artifactId>griffon-miglayout-swing-groovy</artifactId>
</dependency>
Groovy + JavaFX
<dependency>
    <groupId>org.codehaus.griffon.plugins</groupId>
    <artifactId>griffon-miglayout-javafx-groovy</artifactId>
</dependency>

3. Modules

The following sections display all bindings per module. Use this information to successfully override a binding on your own modules or to troubleshoot a module binding if the wrong type has been applied by the Griffon runtime.

3.1. JavaFX

Module name: miglayout-javafx-groovy

Depends on: javafx-groovy

bind(BuilderCustomizer.class)
    .to(MiglayoutJavaFXBuilderCustomizer.class)
    .asSingleton();

The following nodes will become available on a Groovy View

Node Type

migLayoutPane

griffon.javafx.scene.layout.MigLayoutPane

3.2. Swing

Module name: miglayout-swing-groovy

Depends on: swing-groovy

bind(BuilderCustomizer.class)
    .to(MiglayoutSwingBuilderCustomizer.class)
    .asSingleton();

The following nodes will become available on a Groovy View

Node Type

migLayout

net.miginfocom.swing.MigLayout

Both migLayout and migLayoutPane Nodes support the following properties

layoutConstraints

Defines general constraints.

columnConstraints

Defines constraints applicable to columns only.

rowConstraints

Defines constraints applicable to rows only.

4. Examples

The following are usage suggestions for each toolkit. Refer to the MigLayout Cheat Sheet to learn more about the different options that can be used with this layout

4.1. Swing Example

1
2
3
4
5
6
7
8
9
application(title: 'Sample', pack:true, locationByPlatform:true,) {
    migLayout(layoutConstraints: 'fill')

    label 'Username:', constraints: 'left'
    textField columns: 20, text: bind('username', target: model), constraints: 'wrap'
    label 'Password:', constraints: 'left'
    passwordField columns: 20, text: bind('password', target: model), constraints: 'wrap'
    button loginAction, constraints: 'span 2, right'
}

4.2. JavaFX Example

1
2
3
4
5
6
7
8
9
10
11
application(title: 'Sample', sizeToScene: true, centerOnScreen: true) {
    scene(fill: WHITE, width: 300, height: 120) {
        migLayoutPane(layoutConstraints: 'fill') {
            label 'Username:', constraints: 'left'
            textField constraints: 'grow, wrap', text: bind(model.username())
            label 'Password:', constraints: 'left'
            passwordField constraints: 'grow, wrap', text: bind(model.password())
            button loginAction, constraints: 'span 2, right'
        }
    }
}

4.3. FXML Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import griffon.javafx.scene.layout.MigLayoutPane?>

<MigLayoutPane xmlns:fx="http://javafx.com/fxml"
          fx:controller="org.example.SampleController"
          layout="fill"
          cols="[label, pref!][grow, 50::]"
          rows="">
    <Label text="Username:" MigLayoutPane.cc="left" />
    <TextField MigLayoutPane.cc="grow, wrap" />
    <Label text="Password:" MigLayoutPane.cc="left" />
    <PasswordField MigLayoutPane.cc="grow, wrap" />
    <Button fx:id="loginActionTarget"
            mnemonicParsing="false"
            prefWidth="200.0"
            text="Login"
            MigLayoutPane.cc="span 2, right"/>
</MigLayoutPane>