Java 将ReadOnlyObjectWrapper值获取到标签
我已经想了几天如何解决这个问题,但我需要有人的帮助。 我有两个表视图,其中一个是填充数据。若客户点击了某一行,它就会将该行转到另一个tableview。但问题在于总价格,它应该动态地添加用户选择的任何项目。 我得到了这个代码,这是完美的,但我似乎不能得到总标签,而不是在一行 型号Java 将ReadOnlyObjectWrapper值获取到标签,java,javafx,Java,Javafx,我已经想了几天如何解决这个问题,但我需要有人的帮助。 我有两个表视图,其中一个是填充数据。若客户点击了某一行,它就会将该行转到另一个tableview。但问题在于总价格,它应该动态地添加用户选择的任何项目。 我得到了这个代码,这是完美的,但我似乎不能得到总标签,而不是在一行 型号 private final ReadOnlyObjectWrapper<Double> total = new ReadOnlyObjectWrapper<>(); publ
private final ReadOnlyObjectWrapper<Double> total = new ReadOnlyObjectWrapper<>();
public LineItemProperty(String name, Integer quantity, Double unitPrice) {
setName(name);
setQuantity(quantity);
setUnitPrice(unitPrice);
// Obvious binding for the total of this line item:
// total = quantity * unit price
total.bind(Bindings.createObjectBinding(new Callable<Double>() {
@Override
public Double call() throws Exception {
if (quantityProperty().get() == null || unitPriceProperty().get() == null) {
return 0.0;
}else{
return quantityProperty().get() * unitPriceProperty().get();
}
}
}, quantityProperty(), unitPriceProperty()));
}
public class LineItemListWithTotal extends TransformationList<LineItemProperty, LineItemProperty>{
private final TotalLine totalLine;
public LineItemListWithTotal(
ObservableList<? extends LineItemProperty> source) {
super(source);
totalLine = new TotalLine(source);
}
@Override
protected void sourceChanged(ListChangeListener.Change<? extends LineItemProperty> c) {
// no need to modify change:
// indexes generated by the source list will match indexes in this
// list
fireChange(c);
}
另一个全场课程
private final ReadOnlyObjectWrapper<Double> total = new ReadOnlyObjectWrapper<>();
public LineItemProperty(String name, Integer quantity, Double unitPrice) {
setName(name);
setQuantity(quantity);
setUnitPrice(unitPrice);
// Obvious binding for the total of this line item:
// total = quantity * unit price
total.bind(Bindings.createObjectBinding(new Callable<Double>() {
@Override
public Double call() throws Exception {
if (quantityProperty().get() == null || unitPriceProperty().get() == null) {
return 0.0;
}else{
return quantityProperty().get() * unitPriceProperty().get();
}
}
}, quantityProperty(), unitPriceProperty()));
}
public class LineItemListWithTotal extends TransformationList<LineItemProperty, LineItemProperty>{
private final TotalLine totalLine;
public LineItemListWithTotal(
ObservableList<? extends LineItemProperty> source) {
super(source);
totalLine = new TotalLine(source);
}
@Override
protected void sourceChanged(ListChangeListener.Change<? extends LineItemProperty> c) {
// no need to modify change:
// indexes generated by the source list will match indexes in this
// list
fireChange(c);
}
公共类LineItemListWithTotal扩展了TransformationList{
私人最终总额;
public LineItemListWithTotal(
ObservableList我似乎无法得到标签上的总计,而不是一行中的总计
不确定您的确切意思,您是否有一个JavaFX标签
,希望在其上显示值?您的“总价”是否工作?为什么要将此属性添加到LineItemProperty
类中,该类似乎包含有关单个“项目拾取”的数据,如果您试图收集的数据明显依赖于多个项目?您想用转换列表
完成什么?您不想做任何类似于过滤列表
或分类列表
…Thanx的事,让您参与。MikaeIF我有如您所说的Javafx标签和watn来显示每次添加一个项目时的总值。是的,我将获得总值,但仅当我使用tablecolumn初始化它时。这是我要避免的。Fabian是的LineItemProperties只是对象属性,只是以此类推。