How do I get the index of the item selected from a JComboBox?
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. Use : optionsCombo.getSelectedIndex(); inside actionListener Like this : ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Selected: " + optionsCombo.getSelectedItem()); System.out.println(", Position: " + optionsCombo.getSelectedIndex()); }