JavaFX中的ComboBox和ChoiceBox之间的区别 [英] Differences between ComboBox and ChoiceBox in JavaFX

查看:746
本文介绍了JavaFX中的ComboBox和ChoiceBox之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX中的ComboBox和ChoiceBox有什么区别?只是从两个类的Javadoc来看,我还不太清楚。

What are the differences between ComboBox and ChoiceBox in JavaFX? I'm not entirely clear on that just from the Javadoc for both classes.

最终,我需要一个下拉控件,该控件可以在运行时动态重新填充(我在后端有一个数据库)。对于我的应用程序中的所有情况,我只需要从下拉菜单中选择一项。用户也不应从显示的屏幕上向下拉菜单添加选项。

At the end of the day, I need a dropdown control that can be repopulated dynamically at runtime (I've got a database on the backend). For all cases in my application, I only need to select one item from the dropdown menus. The user also shouldn't be able to add an option to the dropdown menu from the screens they are visible on.

我的理解是ComboBox允许用户添加项目到下拉列表并允许选择多个项目,但是从Javadoc看来,可以按照我的需要设置ComboBox,因此它们在某种程度上可以互换。我想在这种情况下,ComboBox的开销比我真正需要的要多,但是还有其他任何事情,只有ComboBox可以做到的,才能将这个决定纳入考虑范围?

My understanding is that ComboBox allows the user to add items to the dropdown list and allows for selecting multiple items, but from the Javadoc it seems like it's possible to setup ComboBox in a way that meets my needs, so it seems like they're interchangeable to some extent. I guess ComboBox has a bit more overhead than I really need in this case, but is there anything else that only a ComboBox could do that would factor into this decision?

编辑

我想我在关键区别上已经回答了我自己的问题,所以我还没有提到别的区别2 ?

I guess I kind of answered my own question on the key differences, so is there something else I've not mentioned that differentiates the 2?

推荐答案

ComboBox 支持 cellFactory ,实际上允许使用任意UI在每个单元格中显示项目。 ChoiceBox 没有此功能,只会在每个单元格中显示文本(您可以使用 转换器 )。

ComboBox supports a cellFactory which allows essentially an arbitrary UI for displaying the item in each cell. ChoiceBox does not have this functionality and will only display text in each cell (which you can configure using a converter).

请参见 http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/combo-box.htm#BABJCCIB 列出了16.5,以显示组合框中的自定义单元工厂的示例。

See http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/combo-box.htm#BABJCCIB listing 16.5 for an example of a custom cell factory in a combo box.

这篇关于JavaFX中的ComboBox和ChoiceBox之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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