I have a ListView control in a JavaFX 2 modal dialog window.
This ListView displays DXAlias instances, the ListCells for which are manufactured by a cell factory. The m
For any body else that ends up on this page:
The correct way of doing this is to supply your observable list with an "extractor" Callback. This will signal the list (and ListView) of any property changes.
Custom class to display:
public class Custom {
StringProperty name = new SimpleStringProperty();
IntegerProperty id = new SimpleIntegerProperty();
public static Callback extractor() {
return new Callback() {
@Override
public Observable[] call(Custom param) {
return new Observable[]{param.id, param.name};
}
};
}
@Override
public String toString() {
return String.format("%s: %s", name.get(), id.get());
}
}
And your main code body:
ListView myListView;
//...init the ListView appropriately
ObservableList items = FXCollections.observableArrayList(Custom.extractor());
myListView.setItems(items);
Custom item = new Custom();
items.add(item);
item.name.set("Mickey Mouse");
// ^ Should update your ListView!!!
See (and similar methods): https://docs.oracle.com/javafx/2/api/javafx/collections/FXCollections.html#observableArrayList(javafx.util.Callback)