美文网首页
2021-05-04_controlsfx常用组件之CheckC

2021-05-04_controlsfx常用组件之CheckC

作者: 微笑碧落 | 来源:发表于2021-05-03 15:51 被阅读0次

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 the check 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 (see titleProperty() property), with or without an indication of how many items have been checked (see showCheckedCountProperty() 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());
     }
 });

5.参考文章2有一个很漂亮的例子

参考文章

1.Class CheckComboBox<T>
2.如何实现Checkbox和ComboBox javaFX?

相关文章

网友评论

      本文标题:2021-05-04_controlsfx常用组件之CheckC

      本文链接:https://www.haomeiwen.com/subject/gshcdltx.html