TrackPane is a custom JavaFX control designed for timeline-like layouts and any scenario where nodes must be positioned along a horizontal axis while avoiding visual collisions.
Each child node is assigned an X coordinate using a layout constraint. During layout, TrackPane automatically places the node into the first available row where it does not overlap with existing items. If a collision is detected, the node is moved to the next available row.
The control handles row assignment, positioning, and relayout automatically while remaining fully compatible with JavaFX styling and layout mechanisms.
- Automatic track assignment
- Horizontal collision detection
- Dynamic relayout on resize or item changes
- Configurable row height
- Configurable row and column spacing
- CSS styling support
- START, CENTER, and END anchor positioning modes
- Timeline-ready architecture
- Scroll-independent design
- Uses standard JavaFX Nodes as children
Each node is associated with:
- A horizontal position (
startX) - An optional anchor mode (
START,CENTER, orEND)
TrackPane uses the node width together with the selected anchor to determine the actual occupied horizontal range.
If that range collides with another node already present in the same row, the node is automatically moved to the next available row.
TrackPane pane = new TrackPane();
Rectangle taskA = new Rectangle(120, 40);
Rectangle taskB = new Rectangle(100, 40);
TrackPane.setStartX(taskA, 100);
TrackPane.setStartX(taskB, 150);
pane.getChildren().addAll(taskA, taskB);