Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX: Bidirectional Binding in FXML

I'm working with JavaFX, and am investigating data binding. I've found that I can define a one-way binding in my FXML, like this:

<TextField fx:id="usernameTextField" text="${controller.userName}" GridPane.columnIndex="1" />

This means, that the text of the usernameTextField is 'observing' the controller.userName property.

But this creates a one-way binding. If the controller.userName property changes, I see the updated text in the text field, that part works. But I can no longer insert text into the text field, because I've made the one-way binding.

All I can find about this are posts which are now more than four years old, but I can't figure out, if JavaFX has been updated to support more elaborate bindings.

like image 256
Troels Avatar asked Oct 27 '25 08:10

Troels


1 Answers

The way to do that is:

<TextField fx:id="usernameTextField" text="#{controller.userName}"/>

But this feature is not enabled yet (last checked on OpenJFX 13) and using it will cause FXMLLoader to throw an UnsupportedOperationException("This feature is not currently enabled.").

like image 187
Miss Chanandler Bong Avatar answered Oct 29 '25 22:10

Miss Chanandler Bong