Javafx 8 : Populating a TableView in initialize method

You replace your TableView in your initialize method.

table =new TableView<Employee>(employees);

You assign the data to the new TableView and leave the one created from the fxml empty.

Instead use the one injected by the FXMLLoader:

@Override
public void initialize(URL location, ResourceBundle resources){
    super.initialize();
    dao = (DAO<Employee>) dFact.getEmployeeDAO();
    try {
        employees = dao.findAll();

        // set data for the table created by the FXMLLoader
        table.setItems(employees);

        // no need to add them to the table since the FXMLLoader is ready doing that
        firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));
        lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));
    } catch (SQLException e) {
        // TODO Mettre une popup erreur base de données
        e.printStackTrace();
    }

}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)