0

我有带有 TableView 和 MySQL 数据库的 JavaFx 应用程序。

我已经从数据库创建实体模型(产品)。

ObservableList<Products> proList;

我如何proList从数据库中填充它然后绑定我的@FXML private TableView<Products> tableView;

我在 JavaFx 中非常新。

谢谢

4

1 回答 1

1

在您的启动/初始化方法中,
首先加载您的实体列表(假设 JPA):

List<Products> productEntityList = 
    entityManager.createQuery("select p from Products p").getResultList(); // or better use your service classes to fetch data

其次用获取的数据初始化 ObservableList:

proList = FXCollections.observableArrayList(productEntityList);

第三个设置表格视图的项目:

tableView.setItems(proList);

请注意,对 proList 所做的任何更改(添加/删除)也将反映到 tableView.getItems()。

于 2012-09-03T14:16:52.157 回答