I\'m trying to create a ChoiceBox
in JavaFX 8, which requires a Collection
. I can\'t figure out how to create a Collection
though... If I
Use the factory methods in FXCollections:
ObservableList<String> list = FXCollections.observableArrayList();
The unsafe operation in your choice box constructor is because you haven't specified the type for the choice box:
ChoiceBox<String> box = new ChoiceBox<>(FXCollections.observableArrayList("Asparagus", "Beans", "Broccoli", "Cabbage" , "Carrot", "Celery", "Cucumber", "Leek", "Mushroom" , "Pepper", "Radish", "Shallot", "Spinach", "Swede" , "Turnip"));
and the error from SortedList
is because there is no constructor taking no arguments. (Again, refer to the javadocs.) There are two constructors: the simplest one takes a reference to an ObservableList
(the list for which the sorted list will provide a sorted view). So you would need something like
SortedList<String> sortedList = new SortedList<>(list);
or
SortedList<String> sortedList = new SortedList<>(FXCollections.observableArrayList());