尝试使用第一个组合选择填充另一个组合框。我不确定为什么这不起作用。想法?
DefaultComboBoxModel typeModel = new DefaultComboBoxModel(new String[]
{"Select Type", "Food", "Drink", "Merchandise"});
typeComboBox.setModel(typeModel);
typeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String type = String.valueOf(typeComboBox.getSelectedItem()).trim();
DefaultComboBoxModel drinkModel = new DefaultComboBoxModel(new String[] {"Select Subtype", "Cocktail", "Bottle Beer", "Draft Beer", "Wine", "N/A"});
DefaultComboBoxModel foodModel = new DefaultComboBoxModel(new String[] {"Select Subtype", "Entree", "Appetizer", "Dessert", "Soup", "Side", "Misc", "Special", "Salad"});
DefaultComboBoxModel merchModel = new DefaultComboBoxModel(new String[] {"Select Subtype", "Clothing", "Misc", "Gift Card", "Glassware"});
switch (type) {
case "Food":
subtypeComboBox.setModel(foodModel);
case "Drink":
subtypeComboBox.setModel(drinkModel);
case "Merchandise":
subtypeComboBox.setModel(merchModel);
default:
subtypeComboBox.setModel(new DefaultComboBoxModel());
}
}
});