Tyler Joe
Tyler Joe

Reputation: 377

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:

double columned combobox

Upvotes: 0

Views: 401

Answers (1)

Reynier Silverio
Reynier Silverio

Reputation: 53

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

Upvotes: 1

Related Questions