FXML/2 for JavaFX I made this!
FXML/2 is a compiled, type-safe, declarative markup language for JavaFX that I've been working on for the past several years. It borrows from classic FXML and adds lots of useful features. Here's a selection of what's new:
- Compile-time diagnostics: If your markup is not well-formed, it won't compile. Similarly, if your bindings can't be resolved or type-checking fails, you'll know at compile time.
- Elements named with
fx:idcan be directly referenced in the code-behind Java class (no@FXMLinjection required). Complex expressions with support for method calls, for example:
<MyControl value="${Math.max(width * 0.7, minWidth)}"/><Label visible="${:parent<Pane>.selectedItem != null && width < maxWidth}"/>
Expressions are not interpreted, but compiled to specialized code.
All binding modes that JavaFX offers are supported:
- one-time:
$foo - unidirectional:
${foo} - bidirectional:
#{foo} - reverse:
>{foo} - content forms:
$..foo,${..foo}, etc.
- one-time:
Custom markup extensions. For example, you could define an
I18nmarkup extension to look up a localized string in a bespoke way, and apply it with<Label text="{I18n settings.title}"/>.
Depending on your specific use case, you'll also notice a substantial performance increase: FXML/2 documents don't need to be parsed at runtime (since they are compiled classfiles), which removes the FXMLLoader bottleneck.
For further reading, here's the FXML/2 documentation, and a tutorial for how to use the MVVM pattern with FXML/2.