gpt4 book ai didi

tableview - 从模型自动更新 TableView 中的行

转载 作者:行者123 更新时间:2023-12-04 13:05:23 28 4
gpt4 key购买 nike

我一直在寻找有关将数据刷新到 tableview 的信息。我试图直接修改模型,但我遇到了一个错误。我修改了模型,但表格没有刷新,只有当我移动一列时,表格才会显示修改后的值。

为了给你展示一个例子(13-6),我拿了教程:

http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJABIEED

我修改了它,包括一个按钮和它的 Action :

Button button = new Button("Modify");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
String name = table.getItems().get(0).getFirstName();
name = name + "aaaa";
table.getItems().get(0).setFirstName(name);
}
});

final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.getChildren().addAll(label, table, button);
vbox.setPadding(new Insets(10, 0, 0, 10));

我猜这是 tableview 中的一个错误,但有没有机会解决这个问题?

谢谢!

最佳答案

要使 TableView 能够跟踪数据更改,您需要将相关字段公开为 JavaFX 属性。将下一个方法添加到 Person教程类:

    public SimpleStringProperty firstNameProperty() {
return firstName;
}

public SimpleStringProperty lastNameProperty() {
return lastName;
}

public SimpleStringProperty emailProperty() {
return email;
}

关于tableview - 从模型自动更新 TableView 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10912690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com