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

2021-05-03  本文已影响0人  微笑碧落

0.前言

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.操作选项

outageCheckComboBox.getItems().addAll()

3.获得用户选择的项目

checkComboBox.getCheckModel().getCheckedItems()

4.用户选择项目后的监听

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?

上一篇 下一篇

猜你喜欢

热点阅读