从组合框中选择多个项目 [英] Selecting multiple items from combobox

查看:120
本文介绍了从组合框中选择多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问我想知道如何更改javafxml组合框的选择模型,以便它可以允许多个选择。感谢任何贡献。

解决方案

你可以试试:


您可以将所需的任何选择模型实例放入ComboBox,但只支持单个选择。我们这样做是因为如果没有对用户界面和用户体验进行重大改变,多项选择并没有真正意义,我们认为未来可以开发一个单独的控件来更好地支持这个用例




来自ControlsFX的CheckComboBox控件是单独控制的。


Pls i want to know how to change the selectionmodel of javafxml combobox so that it can allow multiple seletion. Any contribution will be appreciated thanks.

解决方案

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.

这篇关于从组合框中选择多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆