Looks like one of the listeners added to the combobox tries to process selection. Try to remove the listener(s) from the combo before removing items and readd after.
Exception Removing all Combo Box Items with JComboBox Open
문제
I need to remove all the elements at my JComboBox, using .removeAllItems() it works fine! But I notice that there is a small problem, maybe a bug? I don't know.
If I leave the JComboBox opened, and then try to remove all the items, an exception is thrown:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
I tryed to close the popup before calling the removeAllItems, like this:
private void removeAllClassesAvailable() {
classeComboBox.hidePopup();
classeComboBox.removeAllItems();
}
But still didn't work out !
Maybe because my JComboBox is inside a JTable?
해결책
다른 팁
Try to put a global variable boolean in order to avoid the control keep fireing new events:
public static boolean avoidNewEvents;
.............
private void
jCBoxSubCategoriaActionPerformed(java.awt.event.ActionEvent evt) {
// ComboBox
//
if (Form.avoidNewEvents==false) return;
.............
//Avoid new events to fire recursively
FORM.avoidNewEvents=false;
/
jCBoxSubCategoria.removeAllItems();
//Reset:
FORM.avoidNewEvents=true;
제휴하지 않습니다 StackOverflow