Reputation: 27
ComboBox cmbCategory, cmbType;
I have two ComboBoxes. The 2nd ComboBox
depends on the first ComboBox
.
For example. If I chose "Food" on cmbCategory, the choices on cmbType would be "desert, appetizer..")
How will I do that without clicking a button. I mean when "Food" is chosen on cmbCategory
, the choices for food on cmbType
would showed up automatically without clicking a button. Because what I have come up to is that my cmbType
is hidden and when a button is clicked, then that's the time it will be visible.
I believe this is about MouseListener
or MouseClicked
but I have no idea on how to do it.
Upvotes: 1
Views: 123
Reputation: 57381
You can add an ActionListener to the cmbCategory. On select call getSelectedItem() to get category.
Define a Map> the map should keep the list f items for each category. Fill the map (or you can define some logic to get list of types by selected category). Then just remove all the existing items in cmbType and add new list of types for the selected category.
See the ombobox related code snippets here
Upvotes: 1