I am new to JavaFX and FXML so forgive me if this is a very simple problem. I want to retrieve data from a database (MySQL for instance) and put it in a TableView which is defined in a FXML file. I also want to make this TableView editable and update the database when the user makes some changes.
I've read Mastering FXML
I've found this post but it is not very clear as there are no code examples.
I understand it is possible using DataFX. I don't want to do that.
I understand it is possible to use the controller to retrieve data and populate the table. I don't know how to do the last step. Does anyone have code examples?
Let's say I have a database table people
containing first_name
, last_name
.
My FXML code looks like this:
<GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<Label style="-fx-font: NORMAL 20 Tahoma;" text="Address Book" GridPane.columnIndex="0" GridPane.rowIndex="0">
</Label>
<TableView fx:id="tableView" GridPane.columnIndex="0" GridPane.rowIndex="1">
<columns>
<TableColumn text="First Name"></TableColumn>
<TableColumn text="Last Name"></TableColumn>
</columns>
</TableView>
</GridPane>