• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

capture when user chooses item in JComboBox

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic