Reputation: 89
When I want to shuffle an FilteredList
I get a java.lang.UnsupportedOperationException
.
How to handle this?
Code:
FilteredList<Card> filteredData =
new FilteredList(ob, filterByOption(option.get("selectedCard"), option.get("chapter")));
if (option.get("cardOrder") == "shuffle") {
filterCards=filteredData;
FXCollections.shuffle(filterCards);
}
Upvotes: 4
Views: 269
Reputation: 21809
As written in the documentation:
Wraps an ObservableList and filters it's content using the provided Predicate. All changes in the ObservableList are propagated immediately to the FilteredList.
Therefore, you can shuffle the underlying source ObservableList
instead:
FXCollections.shuffle(ob);
Example:
ObservableList<String> obsList =
FXCollections.observableArrayList("Amanda", "Bill", "Adam", "Albus", "Cicero");
FilteredList<String> fList = new FilteredList<>(obsList, s -> s.startsWith("A"));
System.out.println(fList);
FXCollections.shuffle(obsList);
System.out.println(fList);
Output:
[Amanda, Adam, Albus]
[Adam, Albus, Amanda]
Upvotes: 5