wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes KeyListener is not respond Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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: 188
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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: 188
The idea is to enable the button when I type any key in the JComboBox
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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: 188
like this : findBox.getEditor().addActionListener(this); ?
chen young
Ranch Hand

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

Joined: Sep 09, 2005
Posts: 188
like this : findBox.getEditor().addActionListener(this); ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: KeyListener is not respond
 
Similar Threads
JDialog won't display the another class with Components in JPanel
one key press
ImageObserver interface
Scrollbar not working
best way to update a JList