• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

capture when user chooses item in JComboBox

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
Boost this thread!