将ReadOnlyObjectWrapper值获取到标签

时间:2017-02-02 20:54:06

标签: java javafx

我一直想着如何解决这个问题,但我需要别人的帮助。 我有2个tableviews,其中一个填满了数据。如果客户点击一行,它会将其转到其他tableview。但问题是总价格应该动态添加用户选择的任何项目。 我得到了这个代码并且很完美,但我似乎无法获得总标记而不是连续。

模型

 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()));
        }

视野

   table.getColumns().add(column("Total Price", LineItemProperty::totalProperty, false, null));

    final Label selected = new Label("Total");

另一个类

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);
        }

Thanx很多。任何想法都会有所帮助和赞赏

0 个答案:

没有答案