私は請求書に載っているすべての商品をリストしたい請求表を持っています。私はProductInBill
オブジェクトを請求書のArrayList<ProductInBill>
に保存しました。JavaFX:TableColumnに計算された整数値を追加する方法
私がTableView
を作成したとき、私の共通のアプローチはJavaFXフィールドを作成することでした。コントローラクラスで、私は私のフィールドを持っている:
@FXML public TableColumn<ProductInBill, String> finishedBillProductNameColumn;
@FXML public TableColumn<Integer, Integer> finishedBillProductNumberColumn;
@FXML public TableColumn<ProductInBill, Integer> finishedBillProductPriceBruttoLabel;
@FXML public TableColumn<Integer, Integer> finishedBillProductTotalAmountColumn;
@FXML public TableView finishedBillProductTable;
は、その後、私は次のようなコードでsetUp()
メソッドを使用しています:
private void setUpFinishedBillProductTable() {
finishedBillProductNameColumn.setCellValueFactory(new PropertyValueFactory<ProductInBill, String>("productName"));
finishedBillProductPriceBruttoLabel.setCellValueFactory(new PropertyValueFactory<ProductInBill, Integer>("productPrice"));
}
することも必要ProductInBill
オブジェクトをロードするupdateBillTable()
方法があり、保存しますそれらをTableListに渡してテーブルに渡します。
private void updateFinishedBillProductTable(Bill bill) {
LOG.info("Start reading all Products from Bill");
for(ProductInBill product : bill.getProducts()){
finishedBillProductCurrent.add(product);
}
finishedBillProductTable.getItems().clear();
if(!finishedBillProductCurrent.isEmpty()) {
for (ProductInBill p : finishedBillProductCurrent) {
finishedBillProductTableList.add(p);
}
//here i want to calculate some other Integer values based on the ProductInBill values and insert them to the table too.
finishedBillProductTable.setItems(finishedBillProductTableList);
}
}
これはすべて非常にうまく動作しています。私の問題は今、私はTableView
のフィールドに計算された整数値を持ち、オブジェクト内に保存したくないということです。
たとえば、finishedBillProductNumberColumn
とします。私はArrayList
で繰り返したい、同じ名前を持つすべての製品を見つけ、テーブルに同じアイテムの数を入力します。
どうすればいいですか?私は自分のオブジェクトから値を使って何かを私のTableView
に挿入するだけの解決策を見つけました。