如何在同一个表中添加TableView的一列数据但是执行x操作(如add 5)?
在我的情况下,我想在outTaxColumn中添加inTaxColumn * 0.79的数据。
这是控制器
//Imports
public class ControladorView implements Initializable {
@FXML private TableView tableViewBudget;
@FXML private TableColumn<Product, String> nameBudgetColumn;
@FXML private TableColumn<Product, Double> outTaxColumn;
@FXML private TableColumn<Product, Double> inTaxColumn;
@FXML private TableColumn<Product, Integer> quantityColumn;
private ObservableList<Product> budgetData;
@Override
public void initialize(URL location, ResourceBundle resources) {
//Budget Table
nameBudgetColumn.setCellValueFactory(
new PropertyValueFactory<>("description"));
inTaxColumn.setCellValueFactory(
new PropertyValueFactory<>("price"));
budgetData = FXCollections.observableArrayList();
tableViewBudget.setItems(budgetData);
}
产品类别:
public class Product {
public enum Category {
SPEAKER, HDD, HDD_SSD, POWER_SUPPLY, DVD_WRITER, RAM, SCREEN,
MULTIREADER, MOTHERBOARD, CPU, MOUSE, GPU, KEYBOARD, CASE, FAN
}
public Product(String description, double price, int stock, Category category) {
this.description = description;
this.price = price;
this.stock = stock;
this.category = category;
}
public Category getCategory() {
return category;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
public int getStock() {
return stock;
}
private final String description;
private final double price;
private final int stock;
private final Category category;
}
答案 0 :(得分:2)
你可以做到
outTaxColumn.setCellValueFactory(cellData ->
new SimpleDoubleProperty(cellData.getValue().getPrice() * 0.79 ).asObject());