java - 如何通过操作添加列数据以修改其值

标签 java javafx tableview javafx-8

如何将TableView的一列数据添加到同一个表的其他表中,但执行x操作(如添加5)?

就我而言,我想将 inTaxColumn * 0.79 的数据添加到 outTaxColumn 中。

这是 Controller

//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;
}

最佳答案

你可以做到

outTaxColumn.setCellValueFactory(cellData ->
    new SimpleDoubleProperty(cellData.getValue().getPrice() * 0.79 ).asObject());

关于java - 如何通过操作添加列数据以修改其值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36259812/

相关文章:

ios - tableView 中的无限 backgroundView

java - 客户端和服务器套接字之间交换的 "messages"结尾

java - 在 javafx 应用程序中使用 HTML5 视频标签

JavaFX 不通过 stop() 方法停止应用程序

javafx如何在运行时将按钮图像复制到另一个?

tableview - javafx 准确显示表格 View 中单元格的文本

ios - 如何强制按钮停留在 tableView 单元格的底部?

Java - TCP 服务器无法从 TCP 客户端读取

java - 谁能知道如何使用 android 在 facebook 上发布照片作为评论?

java - 复合组件中的阶段监听器从未被调用过