无法看到注入TableView对象的数据,但可以选择它

时间:2014-01-13 13:41:02

标签: javafx fxml

真的不知道这里有什么问题.. UI是使用JavaFX Scene Builder创建的... 我正在使用Cell Value Factory用Controller对象中的数据填充TableView组件:

final ObservableList<Product> data = FXCollections.observableArrayList(
                new Product("milk UHT 3,2%", "2", "3,55"),
                new Product("milk UHT 3,2%", "2", "3,55"),
                new Product("milk UHT 3,2%", "2", "3,55"),
                new Product("milk UHT 3,2%", "2", "3,55"),
                new Product("milk UHT 3,2%", "2", "3,55")

        );

        productNameColum.setCellValueFactory(new PropertyValueFactory<Product, String>("description"));
        productQuantityColum.setCellValueFactory(new PropertyValueFactory<Product, String>("quantity"));
        productPriceColum.setCellValueFactory(new PropertyValueFactory<Product, String>("price"));

        receiptTable.setItems(data);

这是我的属性对象:

private class Product{
        private SimpleStringProperty description;
        private SimpleStringProperty quantity;
        private SimpleStringProperty price;


        private String getDescription() {
            return description.get();
        }

        private SimpleStringProperty descriptionProperty() {
            return description;
        }

        private void setDescription(String description) {
            this.description.set(description);
        }

        private String getQuantity() {
            return quantity.get();
        }

        private SimpleStringProperty quantityProperty() {
            return quantity;
        }

        private void setQuantity(String quantity) {
            this.quantity.set(quantity);
        }

        private String getPrice() {
            return price.get();
        }

        private SimpleStringProperty priceProperty() {
            return price;
        }

        private void setPrice(String price) {
            this.price.set(price);
        }

        private Product(String name, String quantity, String price) {
            this.description = new SimpleStringProperty(name);
            this.quantity = new SimpleStringProperty(quantity);
            this.price = new SimpleStringProperty(price);
        }
    }

启动它后,我的桌子上装满了看不见的数据:) 我可以选择但却看不到任何东西:

http://i.stack.imgur.com/nhFxD.png

1 个答案:

答案 0 :(得分:2)

Product课程的所有Getter和Setter都是私有的。 Product的获取者必须为public

private class Product{
        private SimpleStringProperty description;
        private SimpleStringProperty quantity;
        private SimpleStringProperty price;


        public String getDescription() {
            return description.get();
        }

        private SimpleStringProperty descriptionProperty() {
            return description;
        }

        private void setDescription(String description) {
            this.description.set(description);
        }

        public String getQuantity() {
            return quantity.get();
        }

        private SimpleStringProperty quantityProperty() {
            return quantity;
        }

        private void setQuantity(String quantity) {
            this.quantity.set(quantity);
        }

        public String getPrice() {
            return price.get();
        }