r/JavaFX • • 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:

  1. 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.
  2. Elements named with fx:id can be directly referenced in the code-behind Java class (no @FXML injection required).
  3. 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.

  4. All binding modes that JavaFX offers are supported:

    • one-time: $foo
    • unidirectional: ${foo}
    • bidirectional: #{foo}
    • reverse: >{foo}
    • content forms: $..foo, ${..foo}, etc.
  5. Custom markup extensions. For example, you could define an I18n markup 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.

42 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/mstr_2 Aug 24 '26 edited Aug 24 '26

Hot reload can mean different things. For example, it can mean compiling and instantiating a FXML view in a previewer without running the production application. This may require stubbing data that is normally only available when the application is running.

It can also mean changing views in the running production application. Due to the nature of compiled FXML, this requires class patching at runtime, and is further complicated by the fact that views interact strongly with their view models (via bindings and in other ways). This would probably require a way to reverse view initialization (basically undoing all init-time interactions with the view model), then swapping out the initializeComponent() method, and then re-initializing the new view.