gpt4 book ai didi

java - 在 TableView Javafx 中插入数据

转载 作者:行者123 更新时间:2023-12-01 14:53:28 27 4
gpt4 key购买 nike

我正在尝试将数据插入到 Javafx TableView 中,实际上我做到了,但它用以下字符串填充了该行:

IntegerProperty [值:72] 等...

如何只显示行中填充的值?

我的TableView代码:

@FXML TableView tableView = new TableView<MetaDadosInfo>();
@FXML javafx.scene.control.TableColumn instituicaoCol;
@FXML javafx.scene.control.TableColumn anoCol;
@FXML javafx.scene.control.TableColumn tamanhoCol;
@FXML javafx.scene.control.TableColumn tipoCol;
@FXML javafx.scene.control.TableColumn nomeCol;

final ObservableList<MetaDadosInfo> data = FXCollections.observableArrayList(
new MetaDadosInfo(codigoInstituicao, ano, size, type, name));

instituicaoCol.setCellValueFactory(
new PropertyValueFactory<MetaDadosInfo, String>("codigoInstituicao"));

anoCol.setCellValueFactory(
new PropertyValueFactory<MetaDadosInfo, String>("ano"));

tamanhoCol.setCellValueFactory(
new PropertyValueFactory<MetaDadosInfo, String>("size"));

tipoCol.setCellValueFactory(
new PropertyValueFactory<MetaDadosInfo, String>("type"));

nomeCol.setCellValueFactory(
new PropertyValueFactory<MetaDadosInfo, String>("name"));

tableView.setItems(data);

MetaDadosInfo 类:

public class MetaDadosInfo {
private SimpleIntegerProperty codigoInstituicao;
private SimpleIntegerProperty ano;
private SimpleLongProperty size;
private SimpleStringProperty type;
private SimpleStringProperty name;

public MetaDadosInfo(int codigoInstituicao, int ano, long size, String type, String name) {
this.codigoInstituicao = new SimpleIntegerProperty (codigoInstituicao);
this.ano = new SimpleIntegerProperty (ano);
this.size = new SimpleLongProperty (size);
this.type = new SimpleStringProperty (type);
this.name = new SimpleStringProperty (name);
}

public SimpleIntegerProperty getCodigoInstituicao() {
return codigoInstituicao;
}

public void setCodigoInstituicao(SimpleIntegerProperty codigoInstituicao) {
this.codigoInstituicao = codigoInstituicao;
}

public SimpleIntegerProperty getAno() {
return ano;
}

public void setAno(SimpleIntegerProperty ano) {
this.ano = ano;
}

public SimpleLongProperty getSize() {
return size;
}

public void setSize(SimpleLongProperty size) {
this.size = size;
}

public SimpleStringProperty getType() {
return type;
}

public void setType(SimpleStringProperty type) {
this.type = type;
}

public SimpleStringProperty getName() {
return name;
}

public void setName(SimpleStringProperty name) {
this.name = name;
}

}

最佳答案

错误出现在我的 MetaDadosInfo 类的 getter 和 setter 中,正确的方法是:

public class MetaDadosInfo {
private SimpleIntegerProperty codigoInstituicao;
private SimpleIntegerProperty ano;
private SimpleLongProperty size;
private SimpleStringProperty type;
private SimpleStringProperty name;

public MetaDadosInfo(int codigoInstituicao, int ano, long size, String type, String name) {
this.codigoInstituicao = new SimpleIntegerProperty (codigoInstituicao);
this.ano = new SimpleIntegerProperty (ano);
this.size = new SimpleLongProperty (size);
this.type = new SimpleStringProperty (type);
this.name = new SimpleStringProperty (name);
}

public int getCodigoInstituicao() {
return codigoInstituicao.get();
}

public void setCodigoInstituicao(int codigoInstituicao) {
this.codigoInstituicao.set(codigoInstituicao);
}

public int getAno() {
return ano.get();
}

public void setAno(int ano) {
this.ano.set(ano);
}

public Long getSize() {
return size.get();
}

public void setSize(long size) {
this.size.set(size);
}

public String getType() {
return type.get();
}

public void setType(String type) {
this.type.set(type);
}

public String getName() {
return name.get();
}

public void setName(String name) {
this.name.set(name);
}

}

关于java - 在 TableView Javafx 中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562027/

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