r/JavaFX • u/john16384 • 6h ago
I made this! FX Flow 0.7.1 released, declarative UI building for JavaFX
I've released FX Flow 0.7.1, a JavaFX utility library focused on declarative UI construction and model driven state, without pulling in a full reactive framework. This release adds editable list backed domains, a ListViewBuilder a new Flex layout, decorators, and a single extensible FX entry point.
Some highlights since the 0.6.1 release:
Flex layout
The new fx-layout module adds Flex, a row/column container whose orientation can change at runtime, and supports an aligned mode in which nested rows and columns coordinate their cells like a grid.
Flex.vflex().aligned()
Flex.hflex().with(
FX.label().text("name"),
FX.textField()
),
Flex.hflex().with(
FX.label().text("email address"),
FX.textField()
)
);This will result in a form like layout where the two text fields are nicely aligned even though the labels are of a different length; see fx-layout/README.md for the full guide.
A single FX entry point
FX is now CoreFX.FX, combining Controls, Panes and Shapes behind one static import:
import static org.int4.fx.builders.CoreFX.FX;There also narrower Controls.CONTROLS, Panes.PANES and Shapes.SHAPES entry points available. Applications can extend CoreFX with their own default methods and expose their own FX field, allowing you to easily extend what (pre-configured) builders are available for use, for example:
public interface AppFX extends CoreFX {
default LabelBuilder header(String text) {
return label("header").text(text);
}
AppFX FX = new AppFX() {};
}Then do:
import static org.myapp.AppFX.FX;...to be able to use your own extensions while all standard builders remain available for use.
Editable, list backed domains
Domains in FX Flow are always immutable and can be freely exchanged on models. Updating a domain backed by a large list is cumbersome though: changing the valid values means building a new domain with all the values copied over.
To solve this problem, models now support a DomainSource which provides the new domain and the changes that produced it each time an editor modifies the domain.
It works like this:
// A domain and its editor:
ListEditor<String> firstNames
= Domain.of("Alice", "Bob", "Charles").editor();
// An editor is a DomainSource and models can use it:
ChoiceModel<String> selectedName = ChoiceModel.of(firstNames);
// Bind the model to a ComboBox or ListView (or both)
ListView<String> listView = FX.listView().model(selectedName).build();
ComboBox<String> comboBox = FX.comboBox().model(selectedName).build();
// Make a change to the list:
firstNames.add("Fred"); // updates listView and comboBoxAll domains are still immutable. When an item is added via the editor, a new domain is created and picked up by the choice model. The ListView and ComboBox subscribe to these changes and update only what's changed. The actual data you see is always backed by the latest immutable domain emitted by the editor.
The list domains are backed by a copy-on-write B-Tree list structure (see BTreeList ). In effect it means copying a list domain is a constant time operation, and modifying a list domain only copies small parts of its list. Very large lists can therefore back domains, and there is no additional storage needed to display them in a control (or even multiple controls) as an ObservableList bridge is provided backed by the domain's contents.
Decorators
Wrapping a node in another node -- to add scrolling or mouse resizing, for example -- usually breaks the fluent chain and forces you to keep the wrapper's visibility in sync by hand. Decorators make it one step: decorate(...) wraps the current builder in a capability-providing node and returns the wrapper's builder, so wrapper specific options stay available and the result can be decorated again:
ResizablePane pane = FX.vbox("form")
.nodes(FX.label().text("Name"), FX.textField().promptText("Name"))
.decorate(ScrollPaneDecorator.INSTANCE)
.fitToWidth()
.decorate(ResizablePaneDecorator.INSTANCE)
.build();ScrollPaneDecorator and ResizablePaneDecorator are included. Wrappers follow the visibility and managed state of their content instead of being configured independently, so they disappear when their content does. Decorator is a functional interface, so you can add decorators for your own node types.
Feedback and suggestions are welcome.
GitHub: https://github.com/int4-org/FX Release: https://github.com/int4-org/FX/releases/tag/0.7.1







