[英]Nested JComboBoxes in Java
I've created a JComboBox
and when I choose an option from the combo box I want to add another combo box (for choosing more specific details) for the selected option.我创建了一个
JComboBox
,当我从组合框中选择一个选项时,我想为所选选项添加另一个组合框(用于选择更具体的细节)。 Is this possible?这可能吗?
I've tried creating another JComboBox
in the original combo box's actionPerformed
class, but I didn't solve the problem.我已经尝试在原始组合框的
actionPerformed
类中创建另一个JComboBox
,但我没有解决问题。
The result should look something like this:结果应该是这样的:
Regarding adding a new JComboBox
: Rather than actionPerformed
try with JComboBox.addItemListener(ItemEvent)
.关于添加新的
JComboBox
:而不是actionPerformed
尝试使用JComboBox.addItemListener(ItemEvent)
。 This is the right place to get the selected item and therefore to create and populate a new JComboBox
with details you want to include.这是获取所选项目的正确位置,因此可以使用要包含的详细信息创建和填充新的
JComboBox
。 Here a link to a demo project in GitHub这是GitHub 中演示项目的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.