0
真的不知道这里有什么问题.. UI是使用JavaFX Scene Builder创建的...... 我使用Cell Value Factory来填充TableView与控制器对象中的数据组成:无法看到数据注入到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
非常感谢RAM! – sw1
问题是我正在使用内部类。将它与控件分离后,它将正常运行 – sw1
如果该类是内部类,则无关紧要。如果Getter是私有的,PropertyValueFactory将不会调用它来检索值。 –