Home > Software design >  Why does this only work on designed comboBox and not on hardcoded swing?
Why does this only work on designed comboBox and not on hardcoded swing?

Time:02-01

Newbie question:

So this code here

public void comboItemItemStateChanged(java.awt.event.ItemEvent evt) {  
        ArrayList<String> arrayItem = new ArrayList<>();
        Iterator<String> iter;
        if(comboGroup.getSelectedItem().equals("Betta Fish")){
            comboItem.removeAllItems();
            arrayItem.add("Plakat");
            arrayItem.add("Halfmoon");
            arrayItem.add("Crown Tail");
            arrayItem.add("Double Tail");
            iter = arrayItem.iterator();
            while(iter.hasNext()){
                comboItem.addItem(iter.next());
            }
        }
        else if(comboGroup.getSelectedItem().equals("Snails")){
            comboItem.removeAllItems();
            arrayItem.add("Apple Horn");
            arrayItem.add("RamsHorn");
            arrayItem.add("Pond Snail");
            arrayItem.add("Assassin Snail");
            iter = arrayItem.iterator();
            while(iter.hasNext()){
                comboItem.addItem(iter.next());
            }

works when I try it on comboBoxes from Design tab in NetBeans. But when I try to apply it to my coded ComboBox, I get a message from evt saying Unused method parameters should be removed. Can I get an explanation why and what is the alternative for hardcoded comboBox?

Purpose of code: a dynamic comboBox so whatever I pick from comboBox1 will have each own set of lists for comboBox2

NOTE: I also tried to change comboItemItemStateChanged to just itemStatChanged.

Source code of my project: enter image description here

  •  Tags:  
  • Related