如何在具有多项选择的java swing中创建下拉列表? [英] How to create a drop-down list in java swing with multiple item selection?
问题描述
我知道 JList
和 JComboBox
.我需要 JList
提供的具有多选功能的组合框下拉功能.
I'm aware of JList
and JComboBox
. I need the combo box drop down functionality with multiple selection functionality that JList
provides.
这是因为列表的内容太大,无法使用简单的列表显示.我还需要选择多个项目,否则我会满足于 JComboBox
.
This is because the contents of the list are too huge to be displayed using a simple list. I also need to select multiple items, otherwise I would have been content with JComboBox
.
有什么建议吗?
推荐答案
使用多选时,最好使用列表而不是组合框.在 GUI 比喻中,人们希望组合框是单选,而列表可以是.
When using multi-select, it's better to use a list than a combo box. As GUI metaphors go, people expect a combo box to be single select, whereas lists can be either.
列表内容太大,无法使用简单列表显示
the contents of the list are too huge to be displayed using a simple list
将 JList
放在 JScrollPane
中.您可以调用 setVisibleRowCount(int) 在 JList
上指定一次应该显示多少行.
Place the JList
in a JScrollPane
. You can call setVisibleRowCount(int) on the JList
to specify how many rows at a time should be shown.
这篇关于如何在具有多项选择的java swing中创建下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!