java—如何在其他数据库中添加列数据,并通过操作修改其值

h43kikqp  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(380)

如何将tableview的一列的数据添加到同一个表的另一列,但执行x操作(如add5)?
在我的例子中,我想将intaxcolumn*0.79的数据添加到outtax列。
这是控制器

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

lstz6jyr1#

你能做到的

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

相关问题