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