This is how I created my JComboBox -
String[] options = {"First", "Second" , "Third"};
JComboBox optionsCombo = new JComboBox(options);
When one of these items is selected, how do i get the index of the item which was selected ? I don't want the item the item that was selected.
int index = optionsCombo.getSelectedIndex()
will give selected index. Use this in combo box action listener
indexes starts from 0,1,2,.. if you want to get the index of selected item then do this
optionsCombo.getSelectedIndex()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With