0.前言
- ComboBox只能选择一个选项,当要选择多个选项的时候,就需要CheckComboBox。
- CheckComboBox属于controlsfx的一个组件。使用前要先安装controlsfx
- 使用方法和ComboBox类似
- 这个组件还是很有用的,但是网上资料很少,找了半天才找到这个。
-
长这个样:
CheckBomboBox
-
默认情况下,titile为用户选择了的项目的标题之和:
标题显示
- 官方文档介绍:
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 thecheck model
.
The title shown in the combobox is, by default, a concatenation of the selected items but this behaviour can be changed and it is possible to set a fixed title (seetitleProperty()
property), with or without an indication of how many items have been checked (seeshowCheckedCountProperty()
property).
1.创建并指定options
CheckComboBox<String> checkComboBox = new CheckComboBox<String>(strings);
2.操作选项
- 注意。。CheckComboBox没有ComboBox的
setItems()
方法。只能如下操作:
outageCheckComboBox.getItems().addAll()
3.获得用户选择的项目
checkComboBox.getCheckModel().getCheckedItems()
4.用户选择项目后的监听
- 事实上是监听getCheckedItems()返回的可监听list
checkComboBox.getCheckModel().getCheckedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
while(c.next()) {
//do something with changes here
}
System.out.println(checkComboBox.getCheckModel().getCheckedItems());
}
});
网友评论