Hello everyone,
I need your help to understand the setCellValueFactory method for TableColumn<?, ?> class in JavaFx. I am a necomer to
Java and would like understand what exactly this method does and the context in which it is to be used.
Please consider the following code snippet taken from:
http://code.makery.ch/java/javafx-8-tutorial-part2/
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
@FXML
private void initialize() {
// Initialize the person table with the two columns.
firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
}
I can understand that these methods will populate the cells of the firstnameColumn and lastNameColumn with the firstNameProperty and lastNameProperty correspondingly. However some important and few trivial things I don't understand:
Q1. There is no mention of the Person object (bean) from which the firstNameProperty is extracted in the code. How does the method know what is going to be passed to it? After all, "cellData" is just a dummy argument for the lambda expression to work.
Q2. After this method has run, how do we get the first person in the first row of the column, second person in the second row of the column and so on? I don't see any code that populates the corresponding entry based on the cell location.
Q3. Trivial question: What does the term "Factory" signify in the method name "setCellValueFactory". Does it indicate some type of Factory API or does it mean that this method is literally a factory of cell values?
Thank you so much for your time and effort,
Anand