JAutoLayout is a constraint-based layout management library based on the kiwi implementation of the Cassowary linear arithmetic constraint-solving algorithm. It allows you to lay out components in (Java) Swing using Apple's Visual Format Language (VFL).
In pom.xml, add the following at the end of the <repositories> section:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Then, add the following to the <dependencies> section:
<dependency>
<groupId>com.github.kausko</groupId>
<artifactId>Jautolayout</artifactId>
<version>-SNAPSHOT</version>
</dependency>
In build.gradle, add the following at the end of the repositories section:
maven { url 'https://jitpack.io' }
Then, add the following to the dependencies section:
implementation 'com.github.kausko.JAutoLayout:-SNAPSHOT'
Notes:
- Only works with Java 17 and above
- The
-SNAPSHOTversion is the latest commit on the main branch. It can be replaced with a specific commit hash or tag. - For Kotlin DSL, use
url = uri("https://jitpack.io")andimplementation(...).
importorg.JAutoLayout.JAutoLayout;
publicclassExample {
publicstaticvoidmain(String[] args) {
// ...varbutton1 = newJButton("button1");
varbutton2 = newJButton("button2");
varviewNames = newHashMap<String, Component>();
viewNames.put("button1", button1);
viewNames.put("button2", button2);
// VFL for equal width buttonsvarconstraints = """ [button1(==button2)] |-[button1]-[button2]-| V:[button1(==button2)] """;
varlayout = newJAutoLayout(constraints, viewNames);
varpanel = newJPanel(layout);
panel.add(button1);
panel.add(button2);
// ...
}
}