javaremoveall

Clearing a dropdown counter in Java?


I need to clear all the fields in several arrays to re-load a new template to parse. I currently set up a function to clear all the relevant array lists and counts. Those are working fine except I am having a hard time clearing out obrDD inside my clearMicroArray() function. Here is my current code (without logic to clear obrDD). How can I clear the dropdown information inside my function?

    static void clearMicroArray() {
    fullMicroArray.clear();
    int returnSize = fullMicroArray.size();
    System.out.println("size of full array" + returnSize);
    obrCount = 0;
    fileRowCount = 0;
    // obr List
    obrList.removeAll(obrList);
    obxList.removeAll(obxList);
};

// Populating the OBR number in dropdown
public static void populateOBRDropdown(JComboBox<String> obrDD) {
    for (int i = 0; i < fullMicroArray.size(); i++) {
        if (fullMicroArray.get(i).substring(0, fullMicroArray.get(i).indexOf("|")).equals("OBR")) {
            i++;
            obrCount++;
            obrDD.addItem("OBR " + obrCount);
        }
    }
}

Solution

  • obrDD is a JComboBox object that you pass into populateOBRDropdown. Your clearMicroArray method, however, also needs obrDD as an input in order for you to do anything with it. Once you pass a reference to the JComboBox, you can call removeAllItems or removeItem from clearMicroArray.