JavaFX bidirectional binding of Array<String> to multiple TextFields

212 views Asked by At

I need your help. In my entity model class I have currently

protected ObservableList<Double> marketSize = FXCollections.observableArrayList(); 
ListProperty<Double> marketSizeProperty = new SimpleListProperty<Priority>(marketSize);

In the UI I have a fixed number of 5 TextFields like so enter image description here

In the fxml file

<TextField fx:id="sizeLYTextField" GridPane.columnIndex="2" GridPane.rowIndex="3">
<TextField fx:id="sizeLY1TextField" GridPane.columnIndex="3" GridPane.rowIndex="3">
<TextField fx:id="sizeLY2TextField" GridPane.columnIndex="4" GridPane.rowIndex="3">

and so on.

Is there a way to bind each of the TextFields in the UI to a different element of the array? Like

sizeLYTextField.textProperty().bindBidirectional(model.marketSizeProperty.get(0));

what is obviously not working.

I thought about an array of StringProperties, but since I have a number of rows beneath each other, each having 5 TextFields I would have quite a number of single StringProperty boiler plate code. Maybe TextFields are not the ideal UI element?! Let me know what you think. Thank you in advance.

0

There are 0 answers