简体   繁体   中英

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. Is this possible?

I've tried creating another JComboBox in the original combo box's actionPerformed class, but I didn't solve the problem.

The result should look something like this:

双列组合框

Regarding adding a new JComboBox : Rather than actionPerformed try with 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. Here a link to a demo project in GitHub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM