Chris
I am not sure what you are trying to do or what your exact problem is. But let me review what I understand about setCellValueFactory.
setCellValueFactory is used to associate a column in a TableView with a property of a class that contains the data to be displayed in the TableView's column. An ObservableList will then be created containing several instances of the class, each containing data. A row in the table will be created for each instance of the class.
For example, here is a class containing several properties.
Now that the class is created, instances of the class are created and placed into an ObservableList. Here is an example of this:
This ObservableList has two entries so the TableView will have two rows.
The last thing to do is to associate the columns in the TableView with properties in the class in the ObservableList. That is done with the setCellValueFactory method. There are two ways to use this method.
Method 1 (the old method)
This informs the TableViewColumn that it will acquire the data for the column named "colStudy" from the property named "parameter". Note that rather than hardcoding the property name, you could also put a string variable in as follows:
This would allow you to dynamically name the property.
Method 2 (new method using lambda expression)
This method allows you to assign the column to the property in a more direct manner without using a fixed string. Note that in the case above, parameterProperty is a SimpleStringProperty. Had the property been a SimpleIntegerProperty, you would have to modify the statement by adding the AsObject method as follows:
I am not sure I am answering your question, but I hope I have shed some light on the purpose of setCellValueFactory. Here is a link to an article that explains this procedure a bit further.
Table View Documentation
I am not sure this will help you to dynamically add columns. I read somewhere that it might be better to use
DataFX.
Let me know if this helped. Also let me know if it didn't. Maybe I can help more once I have a better understanding of where your problem is.
Clark