JavaFX: how to use ListProperty?








when adding element to ListProperty, like below:
ListProperty<String> members = new SimpleListProperty<String>();
members.add("John");
members.add("David");
it throws UnsupportedOperationException
java.lang.UnsupportedOperationException
  at java.util.AbstractList.add(AbstractList.java:148)
  at java.util.AbstractList.add(AbstractList.java:108)
  at java.util.AbstractCollection.addAll(AbstractCollection.java:334)
  at javafx.beans.binding.ListExpression.addAll(ListExpression.java:280)
The problem was that the ListProperty was not properly initialized. To make it work, see the following code
ObservableList<String> observableList = FXCollections.observableArrayList(new ArrayList<String>());
ListProperty<String> members = new SimpleListProperty<Priority>(observableList);
members.add("John");
members.add("David");







see also




No comments:

Post a Comment