ChoiceBox provides a selection of preset values the user can choose from as a new value for the edited cell.
To use a ChoiceBox, we need to have an additional list of the potential new values:
// chaptep10/list/ChoiceBoxListCellDemo.javaObservableList<String> values = FXCollections.observableArrayList( "Red", "Blue", "Yellow", "Green"); ObservableList<String> items = FXCollections.observableArrayList( "Gray", "Gray", "Gray", "Gray"); ListView<String> list = new ListView<>(items);list.setEditable(true);list.setCellFactory(ChoiceBoxListCell.forListView(values));
Note that existing items in the ListView are not required to be chosen from values:
ComboBoxListCell works the same way, providing ComboBox instead ...