This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes KeyListener is not respond Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "KeyListener is not respond" Watch "KeyListener is not respond" New topic
Author

KeyListener is not respond

chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 177
Hi,

I created a JDialog with a JComboBox
I add KeyListener support for the JComboBox but there is no response whenever I press any button on the keyboard.

Here is the code:








Any suggestion why it’s not responding ?


Thanks
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Does the combo box have focus? It will need to be the focused item in order for it to process key input.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Also, depending on what you are trying to accomplish with a KeyListener on a JComboBox you might not be adding the listener to the appropriate element.
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 177
The idea is to enable the button when I type any key in the JComboBox
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

angus young wrote:The idea is to enable the button when I type any key in the JComboBox


Then you probably need to assign the key listener to the editor of the JComboBox. In edit mode, a JComboBox uses a text field and that is the element you need to add the listener to since it is what gains focus.
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 177
like this : findBox.getEditor().addActionListener(this); ?
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 177
like this : findBox.getEditor().addActionListener(this); ?
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 177
like this : findBox.getEditor().addActionListener(this); ?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: KeyListener is not respond
 
Similar Threads
best way to update a JList
JDialog won't display the another class with Components in JPanel
one key press
Scrollbar not working
ImageObserver interface