我将 2 个 JComboBox 组件添加到我的 GUIproductComboBox
和categoryComboBox
中,并为每个组件定义了以下项目侦听器:
categoryComboBox.addItemListener(new GoItemListener());
productComboBox.addItemListener(new ProductItemListener());
用户首先选择一个产品,然后侦听器应根据选择的产品填充类别框。我的项目监听器是内部类。
ProductItemListener
调用如下所示的方法populateCategories
:
protected void populateCategories() {
String product = productComboBox.getSelectedItem().toString();
myMediaDataAccessor.init(product);
ArrayList categoryArrayList = null;
categoryArrayList = myMediaDataAccessor.getCategories();
Iterator iterator = categoryArrayList.iterator();
String aCategory;
while (iterator.hasNext()) {
aCategory = (String) iterator.next();
categoryComboBox.addItem(aCategory.toString());
}
}
我的productComboBox
音乐和视频中有两个产品项目。如果我选择音乐,那么我categoryComboBox
会使用 ArrayList 中的字符串正确填充。
问题是,如果我选择视频,我的categoryArrayList
包含正确的 ArrayList 字符串,所以我的数据被返回并似乎添加到了categoryComboBox
,因为我没有收到任何异常,只是我categoryComboBox
从 GUI 中消失了。
有任何想法吗?
谢谢