This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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?
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic