0

I have JavaFx application with TableView and MySQL database.

I have create entity model(Products) from database.

Have ObservableList<Products> proList;

How i can fill this proList from database and then bind my @FXML private TableView<Products> tableView;?

Im very very new in JavaFx.

Thanks

1 Answer 1

1

In your start/initialize method,
First load your entity list (assuming JPA):

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

Second init the ObservableList with fetched data:

proList = FXCollections.observableArrayList(productEntityList);

Third set the items of the table view:

tableView.setItems(proList);

Note that any changes (add/remove) made to proList will be reflected to tableView.getItems() too.

2
  • please tell me how to initilize EntityManager
    – user525717
    Commented Sep 3, 2012 at 14:51
  • 2
    There are sufficient resources about the JPA and entitymanager on the net. Still if you are having difficulties ask here in new question.
    – Uluk Biy
    Commented Sep 4, 2012 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.