문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top