문제

I have a property which wraps an ObservableList. But I cannot figure out how to initialize it. Currently I am doing it like this

ObjectProperty<ObservableList<T>> property = new ChoiceBox<T>().itemsProperty();

which is obviously totally bad practice. Another one was

ObjectProperty<ObservableList<T>> property = new SimpleObjectProperty<ObservableList<T>>();

but this needs later attention which I try to avoid to initialize the internal ObservableList with an empty List.

I search for something like this

ObjectProperty<ObservableList<T>> property = new SimpleObjectProperty<ObservableList<T>>(new ObservableList<T>());
도움이 되었습니까?

해결책

I recommend you to use ListProperty instead of ObjectProperty>

To initialize it do :
ListProperty<Integer> listProperty = new SimpleListProperty<Integer>(FXCollections.<Integer>observableArrayList());

For more information you can read this article ListProperty vs ObjectProperty

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top