我的应用程序中有一个 jcombobox。
我希望它支持多项选择(就像在 jlist 中所做的那样)。
有没有代码示例?
最佳答案
我认为这是不可能的,除非你像你说的那样使用 JList。
JComboBox API报告:
The user can select a value from the drop-down list, which appears at the user's request.
还有一个 JComboBox tutorial :
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 来做到这一点,为每个项目添加一个复选框。请考虑this answer实现这个“解决方案”。
但是,由于以下原因,我认为这不是一个好主意:
关于swing - JcomboBox 多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8471553/