File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 187
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: 15286
    
    6

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


GenRocket - A Test Data Generation Platform
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    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: 187
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: 15286
    
    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: 187
like this : findBox.getEditor().addActionListener(this); ?
chen young
Ranch Hand

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

Joined: Sep 09, 2005
Posts: 187
like this : findBox.getEditor().addActionListener(this); ?
 
jQuery in Action, 2nd edition
 
subject: KeyListener is not respond
 
Similar Threads
one key press
Scrollbar not working
best way to update a JList
ImageObserver interface
JDialog won't display the another class with Components in JPanel