• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

capture when user chooses item in JComboBox

tormod eriksen
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do something when a user chooses an item in a JComboBox.
I want the user to be able to choose an item by clicking the item with the mouse, and also press enter after having found the correct item by scrolling the items by the up and down arrow keys.
I have attached an ActionListener to the JComboBox. My problem is that things also gets done when the user selects the items by scrolling them with the up and down arrow keys (without pressing enter).
I have tried to add a KeyListener, but the listener code isn't processed.
<jcomboboxcomponent>.getEditor().getEditorComponent().addKeyListener(new java.awt.event.KeyAdapter(){
public void keyPressed(KeyEvent e){
//debug code to see if this section is processed
Have I missed something out, or is it other ways to do this?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic