所以我創建了Instrument
類和Controller
類。我用bindingBidirectional()
方法遇到很大問題。當我試圖在Instrument
類中綁定Combobox
屬性與AmountProperty
時,它給了我一個錯誤。[JavaFx]這個綁定有什麼問題?
amount.valueProperty().bindBidirectional(instrument.amountProperty());
我在做什麼錯在這裏?
Controller class
public class Controller implements Initializable{
@FXML
private ComboBox<Integer> amount = new ComboBox<>();
ObservableList<Integer> amountOptions = FXCollections.observableArrayList(0, 5, 10, 25, 50);
Instrument instrument = new Instrument();
@Override
public void initialize(URL location, ResourceBundle resources) {
amount.getItems().addAll(amountOptions);
//THIS ONE IS NOT WORKING
amount.valueProperty().bindBidirectional(instrument.amountProperty());
}}
而且Instrument
類:
public class Instrument {
private IntegerProperty amount = new SimpleIntegerProperty();
public int getAmount() {
return amount.get();
}
public IntegerProperty amountProperty() {
return amount;
}
public void setAmount(int amount) {
this.amount.set(amount);
}
}
你得到什麼錯誤? – assylias
請參閱http://stackoverflow.com/questions/24889638/javafx-properties-in-tableview –
java:找不到適用於bindBidirectional的方法(javafx.beans.property.IntegerProperty) 方法javafx.beans.property.Property.bindBidirectional (javafx.beans.property.Property)不適用 (參數不匹配; javafx.beans.property.IntegerProperty不能轉換爲javafx.beans.property.Property ) 方法 –
Rocky3582