Javafx tableview not showing data in all columns

This question is really a duplicate of: Javafx PropertyValueFactory not populating Tableview, but I’ll specifically address your specific case, so it’s clear.

Suggested solution (use a Lambda, not a PropertyValueFactory)

Instead of:

aColumn.setCellValueFactory(new PropertyValueFactory<Appointment,LocalDate>("date"));

Write:

aColumn.setCellValueFactory(cellData -> cellData.getValue().dateProperty());

For more information, see this answer:


Solution using PropertyValueFactory

The lambda solution outlined above is preferred, but if you wish to use PropertyValueFactory, this alternate solution provides information on that.

Background

PropertyValueFactory uses reflection to determine the methods to get and set data values as well as to retrieve bindable properties from your model class. The pattern followed is:

PropertyValueType getName()
void setName(PropertyValueType value)
PropertyType nameProperty()

Where “name” is the string specified in the PropertyValueFactory constructor. The first letter of the property name in the getter and setter is capitalized (by java bean naming convention).

Why your application doesn’t work

You have these three expressions:

new PropertyValueFactory<sresult, String>("DateEntered")
new PropertyValueFactory<sresult, String>("cDesc")
new PropertyValueFactory<sresult, String>("CreatedBy")

For your sample properties, the PropertyValueFactory will look for these methods:

"DateEntered" => getDateEntered()
"cDesc" => getCDesc()
"CreatedBy" => getCreatedBy()

And you have these three getters on your sresult class:

getDateEntered()
getcDesc()
getEnteredBy()

Only getDateEntered() is going to be picked up by the PropertyValueFactory because that is the only matching method defined in the sresult class.

Advice

You will have to adopt Java standards if you want the reflection in PropertyValueFactory to work (the alternative is to not use the PropertyValueFactory and instead write your own cell factories from scratch).

Adopting Java camel case naming conventions also makes it easier for Java developers to read your code.

Leave a Comment