문제

I have a form that has 4 TextFields which I'm trying to track with an ObservableList that has 5 columns. The TableView has an extra column to hold a calculated value (the 5th column in my ObservableList).

The data is dumping fine from the 4 TextFields, but the calculated column comes out blank. I assume this is a problem with my getters and setters, because the value is calculated before I pass it to my data model, AND I just tested the data model, and it is GETTING the value (passed as a parameter).

To not put extraneous code here, I think these are the relevant parts:

// This is (part of) my data model

public static class ItemSale {
   private ItemSale (Double barC, String itemm, Double pricee, 
            Integer quant, Double totsP) {
        this.barCode = new SimpleDoubleProperty(barC);
        this.item = new SimpleStringProperty(itemm);
        this.price = new SimpleDoubleProperty(pricee);
        this.quantity = new SimpleIntegerProperty(quant);
        this.rowPrice = new SimpleDoubleProperty(totsP);

        System.out.println(totsP); // this (also) prints the correct value to the screen

// price * quantity = rowPrice, the calculated value that doesn't show up later

// getter & setter for quantity (works, is a textfield in my form)

    public SimpleIntegerProperty getQuantity() {
        return quantity;
    }
    public void setQuantity(Integer quant) {
        quantity.set(quant);
    }

// getter & setter for rowPrice (doesn't work, is calculated, see below)

    public SimpleDoubleProperty getRowPrice(Double totsP) {
        return rowPrice;
    }
    public void setRowPrice(Double totsP) {
        rowPrice.set(totsP);
    }

// in the Add button action handler, I have this:

            Double rowPP;
            rowPP = qua * pr; //qua = variable for quantity, pr = variable for price
            System.out.println(rowPP); //prints to screen fine

            data.add(new ItemSale(
                    bcode,
                    item.getText(),
                    pr,
                    qua,
                    rowPP
                    ));
도움이 되었습니까?

해결책

Ooops...got it figured out. I was researching another problem and found the answer on JavaFx - How to display SimpleStringProperty value in TableView and, in going through my code, I noticed I had the getter with parameters. Removed the parameters and BOOM! it worked.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top