I'm trying to populate a TableView with data from an ObservableList. I've done this before but for some reason I can't get it to work now. I don't get any exceptions or anything but it simply doesn't add anything to the table.
this question is similar but I identified another issue caused by JPA which made it so the mentioned constructor for Modification
is never executed. Instead JPA does its magic to assign the values.
Here's my code - I snipped code that was irrelevant to the question:
FXML
<TableView fx:id="tblModifications" layoutX="14.0" layoutY="14.0" prefHeight="545.0" prefWidth="512.0">
<columns>
<TableColumn prefWidth="75.0" text="%itemNumber" fx:id="colModArt"/>
<TableColumn prefWidth="75.0" text="%name" fx:id="colModName"/>
<TableColumn prefWidth="75.0" text="%amount" fx:id="colModAmount" />
</columns>
</TableView>
Main.java
public class Main extends Application implements Initializable {
private TableView<Modification> tblModifications;
private TableColumn<ObservableList<Modification>, String> colModArt;
private TableColumn<ObservableList<Modification>, String> colModName;
private TableColumn<ObservableList<Modification>, Integer> colModAmount;
@Override
public void initialize(URL arg0, ResourceBundle arg1){
colModArt.setCellValueFactory(new PropertyValueFactory<>("barcodeProperty"));
colModName.setCellValueFactory(new PropertyValueFactory<>("nameProperty"));
colModAmount.setCellValueFactory(new PropertyValueFactory<>("amountProperty"));
admin = Administration.getInstance();
tblModifications.setItems(admin.observableModifications); // This list is populated with correct data, I tested.
}
@Override
public void start(Stage primaryStage) throws Exception{
resources = ResourceBundle.getBundle("strings", new Locale("NL"));
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("main.fxml"), resources);
primaryStage.setTitle(resources.getString("title"));
primaryStage.setScene(new Scene(root, 1280, 1024));
primaryStage.show();
}
}
Modification.java
public class Modification {
public SimpleStringProperty barcodeProperty;
public SimpleStringProperty nameProperty;
public SimpleIntegerProperty amountProperty;
private int id;
private Seller seller;
private Product product;
private int amount;
private Boolean accepted;
public Modification(int id, Seller seller, Product product, int amount) {
this.id = id;
this.seller = seller;
this.product = product;
this.amount = amount;
this.accepted = false;
barcodeProperty.set(String.valueOf(product.getBarcode()));
nameProperty.set(product.getName());
amountProperty.set(amount);
}
}
Any help in resolving this issue would be greatly appreciated!