How do I get the selected item from a TableView
in JavaFX?
I am currently using
ObservableList selectedItems = taview.getSelectionModel().getSelectedItems();
but that does not return me the one selected item in the selection model.
javajavafxtableview
How do I get the selected item from a TableView
in JavaFX?
I am currently using
ObservableList selectedItems = taview.getSelectionModel().getSelectedItems();
but that does not return me the one selected item in the selection model.
Best Answer
Ok, lets say you have a data model class named
Person
. This way:Note that
TableView
must take aPerson
as a type argument to avoid casting:or
when your row is selected, you will return one
Person
instance. Then do what ever you want with that instance.