productComboBox
GUIに2 つの JComboBox コンポーネントを追加し、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
、ミュージックとビデオの 2 つの商品アイテムがあります。Music を選択するcategoryComboBox
と、ArrayList の文字列が正しく入力されます。
問題は、ビデオを選択すると、categoryArrayList
文字列の正しい ArrayList が含まれているため、categoryComboBox
例外が発生しないため、データが返されてに追加されているように見えることですcategoryComboBox
。GUI から消えるだけです。
何か案は?
ありがとう