Reputation: 93
private final ObservableList<City> cityList = FXCollections.observableArrayList(city
-> new Observable[]{
city.cityNameProperty(),
city.cityLonProperty(),
city.cityLatProperty()});
public ObservableList<City> getCityList() {
return cityList;
}
How can I retrieve the cityNameProperty from one object inside the observableArrayList for setting a listview?
I did
cityView.setItems(cityList.getCityList());
But this is setting the objects ([email protected]), whereas I need the properties of the objects.
Upvotes: 0
Views: 1179
Reputation: 209684
Use a cell factory:
cityView.setCellFactory(lv -> new ListCell<City>() {
@Override
protected void updateItem(City city, boolean empty) {
super.updateItem(city, empty);
setText(empty ? null : city.getCityName());
}
});
Upvotes: 1