Dynamically change JComboBox

前端 未结 4 513
天命终不由人
天命终不由人 2020-12-15 17:32

I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 17:50

    It also works without DefaultComboBoxModel...

    JComboBox op=new JComboBox(new String[] {"d","e","f"});
    op.removeAllItems();
    String[] new_entries=new String[] {"a","b","c"}
    for (String s : new_entries) {
         op.insertItemAt(s, op.getItemCount());
    }
    op.setSelectedIndex(0);
    

    Guess which values you'll see...

提交回复
热议问题