Tableview 不填充 JavaFX



所以我看到了所有已经问过的问题,并尝试了它们,但它不起作用。

这是我的代码:

public class SelectClientInterface implements Initializable {
//Views
@FXML
TableView<String> selectClientTable;
@FXML
TableColumn<String, String> CodeC, NomC, RegCommerceC, IdFiscalC, NArtFisC;
@FXML
Button selectClientButton, returnSelectClientButton;
ObservableList<Clients> mylist = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
populateTable();
}

void populateTable() {
mylist.addAll(clientsArray);
for (Clients client : clientsArray) {
CodeC.setCellValueFactory(c -> new SimpleStringProperty(String.valueOf(client.getCodeC())));
NomC.setCellValueFactory(c -> new SimpleStringProperty(client.getNomC()));
RegCommerceC.setCellValueFactory(c -> new SimpleStringProperty(client.getRegCom()));
IdFiscalC.setCellValueFactory(c -> new SimpleStringProperty(client.getIdFiscal()));
NArtFisC.setCellValueFactory(c -> new SimpleStringProperty(client.getnArticleFiscal()));
System.out.println(String.valueOf(client.getCodeC()) + client.getNomC() + client.getRegCom() + client.getIdFiscal() + client.getnArticleFiscal());
}
}

}

在此处输入图像描述

您使用了错误的类型参数来TableColumnTableView。由于TableView的项目属于Client类型(至少这似乎是意图(,因此您应该使用TableView<Client>TableColumn<Client, String>.

此外,您没有设置TableView项。

你也用错TableColumn.cellValueFactorycellValueFactory用于屏幕上显示TableView的每一行。使用最后一个Client的值会导致最后一个项的值用于每个非空行。相反,您应该使用传递给CallbackTableColumn.CellDataFeatures提供的值。

@FXML
TableView<Client> selectClientTable;
@FXML
TableColumn<Client, String> CodeC, NomC, RegCommerceC, IdFiscalC, NArtFisC;
@FXML
Button selectClientButton, returnSelectClientButton;
ObservableList<Clients> mylist = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
populateTable();
}

void populateTable() {
mylist.addAll(clientsArray);
CodeC.setCellValueFactory(c -> new SimpleStringProperty(String.valueOf(c.getValue().getCodeC())));
NomC.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getNomC()));
RegCommerceC.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getRegCom()));
IdFiscalC.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getIdFiscal()));
NArtFisC.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getnArticleFiscal()));
for (Clients client : clientsArray) {
System.out.println(String.valueOf(client.getCodeC()) + client.getNomC() + client.getRegCom() + client.getIdFiscal() + client.getnArticleFiscal());
}
selectClientTable.setItems(mylist);
}

相关内容

  • 没有找到相关文章

最新更新