ComboBox に 3 つの項目がある場合:
123、456、および 789 の場合、最初のもの (123) のみを取得でき、残りはすべて無視されます。
mainCombo.addPopupMenuListener(new PopupMenuListener() {
ArrayList<Object> selectionSaver = new ArrayList<Object>();
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
if (mainList.getSelectedValue() != null) {
ArrayList<Object> arrayValue = mainMethods.returnArrayList(mainList.getSelectedValue());
for (int i = 0; i < arrayValue.size(); i++) {
mainCombo.addItem(arrayValue.get(i));
}
Object lastSelected = mainCombo.getSelectedItem(); // It gets the bloody first and never the other ones, even when I select them.
selectionSaver.add(lastSelected); // It adds the bloody first that was captured.
System.out.println(selectionSaver); // Prints only the first, because it was selected by default.
}
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
mainCombo.removeAllItems();
}
@Override
public void popupMenuCanceled(PopupMenuEvent arg0) {
// TODO Auto-generated method stub
}
});
非常に不快な問題。コンボボックスはクリックしたとき (ポップアップ) にのみ操作するため、この瞬間に項目を追加してから消去します。それにもかかわらず、最初/タイトルのアイテムは更新されないか、単に空白であり、最後の選択状態をフィールドで保存することはできず、ArrayList を使用して保存することもできません。マウスとアイテムのリスナーを試してみましたが、常に最初の要素を返すため、毎回惨めに失敗しました。
ポップアップ内でのみ処理している場合でも、選択されたものを追跡する方法について何か考えはありますか? ありがとうございます!