Getting selected item from a JavaFX TableView

Ok, lets say you have a data model class named Person. This way:

Person person = taview.getSelectionModel().getSelectedItem();
System.out.println(person.getName());    

Note that TableView must take a Person as a type argument to avoid casting:

@FXML
private TableView<Person> taview;

or

TableView<Person> taview = new TableView<>();

when your row is selected, you will return one Person instance. Then do what ever you want with that instance.

Leave a Comment

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