我有以下课程:
public class Model {
...
private SimpleStringProperty currency;
public SimpleStringProperty currencyProperty() {
if(currency == null){
currency = new SimpleStringProperty();
}
return currency;
}
...
}
我将(textfield)绑定到上面的类,如下所示:
@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());
...
}}
没关系。绑定组合框和复选框怎么样?假设Combobox为
@FXML
private ComboBox<String> cb_currency;
我将值放在init()
方法
cb_currency.getItems().addAll(
"USD", "EUR", "RUB"
);
答案 0 :(得分:3)
cb_currency.valueProperty().bindBidirectional(model.currencyProperty());
工作?