So i am trying to learn how to use JavaFx Tableview and i stumpled across this tutorial:
in this tutorial they show that in order to fill you tableView you have to fill it with Strings, but not just any String you have to format you String to a SimpleStringProperty
i tried without the format and the result was that none of the information would show!
Also i found that if you want to add an Integer to the table you would have to declare it as an SimpleIntegerProperty
Now i am fairly new to JavaFx but does this mean that when i create an object i have to format all my Integers and Strings to be able to fill my TableView? it seems rather stupid but maybe there is a higher purpose? or is there a way to avoid it?
You don’t need to use Properties in your table data objects for them to display, although use of Properties in certain circumstances is desirable.
The following code will display a table of people based on a Person class which has only String fields.
Explanation
The purpose of using Properties and ObservableLists is that these are listenable elements. When properties are used, if the value of a property attribute in the datamodel changes, the view of the item in the TableView is automatically updated to match the updated datamodel value. For example, if the value of a person’s email property is set to a new value, that update will be reflected in the TableView because it listens for the property change. If instead, a plain String had been used to represent the email, the TableView would not refresh as it would be unaware of email value changes.
The PropertyValueFactory documentation describes this process in detail:
Update
Here is a contrasting example to the first example which demonstrates how a TableView can observe and automatically refresh based on changes to it’s ObservableList of items and changes to the value of a property based item attribute.