Hi,
I am trying to add a key Listener to a JComboBox so that when you hit the delete key, it deletes the item selected from the Combo box. Here is the code that registers the listener to the combo box.
jcboCountries.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { System.out.println("In key pressed"); if (e.getKeyCode() == KeyEvent.VK_DELETE){ System.out.println("Delete key hit"); Object item = model.getSelectedItem(); jcboCountries.removeItem(item); } } });
I also added this line to set the combo box focus.
jcboCountries.setFocusable(true);
But when I hit the delete button nothing happens. The println lines don't print. Nothing.
Any help is appreciated.