パネルに JComboBox があります。ポップアップ メニュー項目の 1 つは「その他」で、それをクリックすると、さらにメニュー項目を取得して既存のリストに追加します。この後、ポップアップメニューを開いたままにして、より多くのアイテムがフェッチされたことをユーザーが認識できるようにしたいのですが、ポップアップは閉じます。私が使用しているイベントハンドラーコードは次のとおりです
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == myCombo) {
JComboBox selectedBox = (JComboBox) e.getSource();
String item = (String) selectedBox.getSelectedItem();
if (item.toLowerCase().equals("more")) {
fetchItems(selectedBox);
}
selectedBox.showPopup();
selectedBox.setPopupVisible(true);
}
}
private void fetchItems(JComboBox box)
{
box.removeAllItems();
/* code to fetch items and store them in the Set<String> items */
for (String s : items) {
box.addItem(s);
}
}
showPopup() および setPopupVisible() メソッドが期待どおりに機能しない理由がわかりません。