Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KeyListener of JComboBox

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I add a KeyListener to my comboBox. But When I edit an item of my comboBox(Of course, there are key typed, pressed, released events occured), but no event invoked.
If I use the KeyListener in a wrong way why do a keylistener be added to a comboBox.
Thanks in advance.
PS:If I don't describe it clearly, please let me know.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the absence of any code which demonstrates the problem, I will guess

if you are adding your keylistener like this
comboBox.addKeyListener(...

it should be
comboBox.getEditor().getEditorComponent().addKeyListener(...
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
It works!
Why don't write this in the java tutorial? Or I've not read it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic