I am having trouble updating a tableview with an observable list. When I run the below code I get a table with the first column populated with data (productid) but the rest are not. All PropertyValueFactory instances are called with the proper string name.
<TableView fx:id="productTable" layoutX="92.0" layoutY="319.0" prefHeight="97.0" prefWidth="363.0" GridPane.columnIndex="7" GridPane.columnSpan="5" GridPane.rowIndex="3" GridPane.rowSpan="2">
<columns>
<TableColumn prefWidth="98.0" text="Product ID" fx:id="productID"/>
<TableColumn prefWidth="110.0" text="Product Name" fx:id="productName"/>
<TableColumn prefWidth="131.0" text="Inventory Level" fx:id="productInventoryLevel"/>
<TableColumn prefWidth="128.0" text="Price per Unit" fx:id="productPrice"/>
</columns>
</TableView>
//Controller.java
@FXML private TableView<Product> productTable;
@FXML private TableColumn<Product, String> productID;
@FXML private TableColumn<Product, String> productPrice;
@FXML private TableColumn<Product, String> productName;
@FXML private TableColumn<Product, String> productInventoryLevel;
private ObservableList<Product> productData = FXCollections.observableArrayList(
new Product(0, "Wheel", 100.99, 4, 0, 1),
new Product(1, "Seat", 50.0, 4, 0, 1));
//Product properties declared the same as https://docs.oracle.com/javafx/2/ui_controls/table-view.htm#
private ObservableList<Product> productData = FXCollections.observableArrayList(
new Product(0, "Wheel", 100.99, 4, 0, 1),
new Product(1, "Seat", 50.0, 4, 0, 1));
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
System.out.println("Product ID factories");
productID.setCellValueFactory(new PropertyValueFactory<Product, String>("productID"));
productPrice.setCellValueFactory(new PropertyValueFactory<Product, String>("productPrice"));
productInventoryLevel.setCellValueFactory(new PropertyValueFactory<Product, String>("productInventoryLevel"));
productName.setCellValueFactory(new PropertyValueFactory<Product, String>("productName"));
productTable.setItems(productData);
System.out.println("Set items");
}
//product constructor
public Product(int id, String name, double price, int inStock, int min, int max){
associatedParts = new ArrayList<>();
this.productID = new SimpleIntegerProperty(id);
this.productName = new SimpleStringProperty(name);
this.productPrice = new SimpleDoubleProperty(price);
this.productInStock = new SimpleIntegerProperty(inStock);
this.min = new SimpleIntegerProperty(min);
this.max = new SimpleIntegerProperty(max);
}
public void setName(String name) { productName.set(name); }
public String getName() { return productName.get(); }
public void setPrice(double price) { productPrice.set(price); }
public double getPrice() { return productPrice.get(); }
public int getInStock() { return productInStock.get(); }
public void setInStock(int count) { productInStock.set(count); }
public void setMin(int min) { this.min.set(min); }
public int getMin() { return this.min.get(); }
public void setMax(int max) { this.max.set(max); }
public int getMax() { return this.max.get(); }
public void setProductID(int productId) { productID.set(productId); }
public int getProductID() { return productID.get(); }
public void addAssociatedPart(Object part) { associatedParts.add(part); }
public boolean removeAssociatedPart(int partID){
return false;
}
Here is the getters and setters as requested.What I don't understand is why my productID is working but the others are not when the code is basically identical.