jComboBox1.addItem("New Item");
ArrayList list = new ArrayList<>();
list.add("New Item Collection (1 of 3)");
list.add("New Item Collection (2 of 3)");
list.add("New Item Collection (3 of 3)");
((DefaultComboBoxModel) jComboBox1.getModel()).addAll(list);
int index = jComboBox1.getSelectedIndex();
if (index >= 0) {
jComboBox1.insertItemAt("Inserted Item", index);
}
Note:
index must be >= 0 and <= ItemCount
int index = jComboBox1.getSelectedIndex();
if (index >= 0) {
jComboBox1.removeItemAt(index);
jComboBox1.insertItemAt("Replaced Item", index);
}
int index = jComboBox1.getSelectedIndex();
if (index >= 0) {
jComboBox1.removeItemAt(index);
}
Note:
index must be >= 0 and < ItemCount
jComboBox1.removeAllItems();
System.out.println("Item Count: "+jComboBox1.getItemCount());