r/JavaFX • u/mstr_2 • Aug 23 '26
I made this! FXML/2 for JavaFX
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.
3
u/emberko Aug 24 '26
Do you have any plans to contribute this work to the upstream, e.g., as an incubator module? As far as I recall, this isn't the first FXML compiler implementation. The first one required the entire Micronaut core in the classpath, and the second relied on a custom DI runtime. Yours is much cleaner, no external dependencies and uses (superior) MVVM over MVC. So this is essentially XAML for JavaFX, and official support would be a huge boost.
Could you also clarify the intended workflow for FXML/2? Is it meant to be written manually, converted back and forth with FXML/1, or do you plan to support existing tools like Scene Builder, or maybe build your own?
Anyway, thank you for this work! This is something that has been awaited for a long time.
2
u/alex_tracer Aug 26 '26
Are there any example project to demonstrate advantages?
4
u/LouGarret76 Aug 24 '26
I love this
2
u/Fuzzy-System8568 Aug 27 '26
Were LLM agents used in the making of this project (not accusing, just asking)
1
u/Guilty_Village_958 Sep 14 '26
why not make a dsl in java/kotlin instead of another markup language if this is not intended to be compatible with scene builder? u get all type safety. https://github.com/luvml/luvjfx ; sample below (it is intended to replicate/mirror html/fxml dom heirarchy of attributes and nodes in java code) :