rakamakafo
rakamakafo

Reputation: 1154

How to bindBidirectional comboboxes and checkboxes

I've the following class:

    public class Model {
    ...
    private SimpleStringProperty currency;
    public SimpleStringProperty currencyProperty() {
            if(currency == null){
                currency = new SimpleStringProperty();
            }
            return currency;
        }
    ...
    }

And I bind (textfield) to above class as follows:

@FXMLController("view.fxml")
public class Controller {
...
@FXML
    private TextField tf_acc_num;
@Inject
    private Model model;
...
@PostConstruct
    public void init(){
tf_acc_num.textProperty().bindBidirectional(model.currencyProperty());
...
}}

It is Ok. What about binding comboboxes and checkboxes? Assume Combobox as

@FXML
    private ComboBox<String> cb_currency;

and I put values in it inside init() method

cb_currency.getItems().addAll(
                "USD", "EUR", "RUB"
        );

Upvotes: 2

Views: 2041

Answers (1)

James_D
James_D

Reputation: 209339

Does

cb_currency.valueProperty().bindBidirectional(model.currencyProperty());

work?

Upvotes: 4

Related Questions