JcomboBox多项选择 [英] JcomboBox multiple selection

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

问题描述

我的应用程序中有一个jcombobox. 而且我希望它支持多项选择(就像在jlist中一样). 有代码示例吗?

I have a jcombobox in my application. and i want it to support multiple selection (like it do in a jlist). is there any code example?

推荐答案

我认为这是不可能的,除非您使用JList,如您所说.

I think it's not possible, unless you use a JList, like you said.

JComboBox API 报告:

用户可以从下拉列表中选择一个值,该列表显示在 用户的请求.

The user can select a value from the drop-down list, which appears at the user's request.

和一个JComboBox 教程:

And a JComboBox tutorial:

列表并不是很吸引人,但是它们比 组合框,当项目数很大(例如,超过20个)或 选择多个项目可能是有效的.

Lists are not terribly attractive, but they're more appropriate than combo boxes when the number of items is large (say, over 20) or when selecting multiple items might be valid.

更新:

我查看了此答案,因为实际上可以使用ListCellRenderer进行此操作,并为每个项目添加一个复选框.请考虑此答案以实施此解决方案".

I reviewed this answer, because actually it's "possible" to do that using a ListCellRenderer, adding a checkbox to each item. Please consider this answer to implement this "solution".

但是,由于以下原因,我认为这不是一个好主意:

However, I don't think it's a good idea for the following reasons:

  1. 有一个类似JList的控件,该控件允许多项选择;
  2. JComboBox控件仅用于单项选择;
  3. 对于我来说,仍然使用JComboBox控件并允许多项选择对我来说没有意义.

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

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