3
我有以下類,其中包含價格,數量屬性以及這兩個屬性中的任何更改都應導致事務處理費用的更新。javafx:將屬性綁定在一起並在tableview中顯示它們
public class GroceryCounter {
private DoubleProperty volume;
private DoubleProperty price;
private DoubleBinding transactionFee;
public double getVolume(){
return this.volume.get();
}
public DoubleProperty volumeProperty(){
return this.volume;
}
public void setVolume(double volume){
this.volume.set(volume);
}
public double getPrice(){
return this.price.get();
}
public DoubleProperty priceProperty(){
return this.price;
}
public void setPrice(double price){
this.price.set(price);
}
public double getTransactionFee(){
this.transactionFee = this.price.multiply(this.volume).multiply(0.0025);
return this.transactionFee.getValue();
}
public DoubleBinding transactionFeeProperty(){
return this.transactionFee;
}
}
這是我在我的Controller
類中使用的代碼。
public TableColumn<Trade, Double> transactionFeeColumn;
......
// in the initialize method
transactionFeeColumn.setCellValueFactory(cellData -> cellData.getValue().transactionFeeProperty());
問題:
我不能與下面的消息表列顯示的交易手續費:
類型不匹配:不能從DoubleBinding轉換爲ObservableValue
我覺得很舒服關於上面的代碼安全,因爲我覺得我應該使用getTransactionFee()
而不是transactionFeeProperty()
在tableColumn中顯示結果。
- 我是否正確地將價格屬性和音量屬性綁定到
transactionFee
?
謝謝。
但是,你怎麼能扳平'getTransactionFee()'實例方法到Controller中的TableColumn? – mynameisJEFF
@mynameisJEFF我更新了我的答案。 – Kachna