JavaFX 2.0 TableView in FXML with Data from Database

后端 未结 2 1016
生来不讨喜
生来不讨喜 2021-01-17 03:33

I am wondering how can I retrieve data from a mysql database into a tableview which is into a fxml file. I must retrieve the data and place it into a tableview which is loca

2条回答
  •  耶瑟儿~
    2021-01-17 04:12

    AFAIK, you cannot retrieve and display the data from DB in FXML file, and make the tableview cells editable in FXML file. Even though it was possible (maybe partially through custom Builder and BuilderFactory), it is not recommended to do that in a sense of MVC. Please read about Why Use FXML and its benefits first. Still you can define some basic data structures in FXML file if it is so necessary, see Introduction to FXML.
    So do your non-view related tasks in a initialize() method of the controller, namely retrieve data and set the items of the tableview. Customize the cell factories of the table columns to support editing and so on.

提交回复
热议问题