You could try an ControlsFX CheckComboBox (ControlsFX is a 3rd party controls library for JavaFX).
Just copied from the CheckComboBox javadoc:
A simple UI control that makes it possible to select zero or more items within a ComboBox-like control. Each row item shows a CheckBox, and the state of each row can be queried via the check model.
// create the data to show in the CheckComboBox
final ObservableList<String> strings = FXCollections.observableArrayList();
for (int i = 0; i <= 100; i++) {
strings.add("Item " + i);
}
// Create the CheckComboBox with the data
final CheckComboBox<String> checkComboBox = new CheckComboBox<String>(strings);
// and listen to the relevant events (e.g. when the selected indices or
// selected items change).
checkComboBox.getCheckModel().getSelectedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
System.out.println(checkComboBox.getCheckModel().getSelectedItems());
}
});
}
Note: the JavaFX controls developer lead comments on the in-built combobox control for JavaFX:
you can put whatever selection model instance you want into ComboBox, but only single selection will ever be supported. We did this as multiple selection didn't really make sense without drastic changes to the UI and UX, and we figured a separate control could be developed in the future to better support this use case
The CheckComboBox control from ControlsFX is that seperate control.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…