0

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>());
thatsIch
  • 828
  • 11
  • 23

1 Answers1

3

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

agonist_
  • 4,890
  • 6
  • 32
  • 55
  • Thanks, I was sure I tried this one already, though I missed the generic instantiation of observableArrayList(). Thanks for pointing that out. – thatsIch Oct 17 '13 at 13:09