Java 11 bindings for Taffy 0.13.0, with Flexbox, Grid, Block, float layout, parsing, measurement callbacks, and native binaries for Linux, Windows, and macOS on x86-64 and ARM64.
Add Taffy4J from Maven Central:
repositories {
mavenCentral()
}
dependencies {
implementation("com.antepod:taffy4j:0.13.0-2")
}The artifact includes native libraries for every supported platform; no
separate native dependency or java.library.path configuration is required.
import com.antepod.taffy.geometry.Size;
import com.antepod.taffy.style.AvailableSpace;
import com.antepod.taffy.style.Display;
import com.antepod.taffy.style.Style;
import com.antepod.taffy.tree.Layout;
import com.antepod.taffy.tree.NodeId;
import com.antepod.taffy.tree.TaffyTree;
try (TaffyTree<Void> tree = new TaffyTree<>()) {
NodeId child = tree.newLeaf(Style.builder().size(120.0f, 40.0f).build());
NodeId root = tree.newWithChildren(
Style.builder().display(Display.FLEX).size(640.0f, 480.0f).build(),
child);
tree.computeLayout(root, new Size<>(
AvailableSpace.definite(640.0f),
AvailableSpace.definite(480.0f)));
Layout layout = tree.layout(child);
System.out.println(layout.location.x + ", " + layout.location.y);
}The tree owns native memory, so use try-with-resources. A tree is not thread-safe; synchronize externally if multiple threads share it.
See Getting started, installation, the platform matrix, and layout-change tracking.
Taffy4J can return exact observable layout changes from one native compute and one packed JNI result:
LayoutChanges changes = tree.computeLayoutWithChanges(root, availableSpace);
for (LayoutChange change : changes) {
if (change.geometryChanged()) {
// update retained UI geometry
}
}An optional listener provides the same batch one record at a time after native compute has returned. Existing compute methods keep their original non-tracking native path when no listener is installed.
Taffy4J requires Java 11 or newer. Published classes target Java 11 bytecode.
Taffy4J loads its bundled JNI library with System.load. JDK 24 and newer warn
when native access is not explicitly enabled; a future JDK will deny it by
default. Applications using Taffy4J from the class path should start with:
java --enable-native-access=ALL-UNNAMED ...
For Gradle's application plugin:
application {
applicationDefaultJvmArgs = listOf("--enable-native-access=ALL-UNNAMED")
}