Google Answers Logo
View Question
 
Q: Java action listeners ( No Answer,   2 Comments )
Question  
Subject: Java action listeners
Category: Computers > Programming
Asked by: sebmaynard-ga
List Price: $2.00
Posted: 25 Jun 2005 11:23 PDT
Expires: 30 Jun 2005 13:44 PDT
Question ID: 536968
Hi guys,

This is quite an urgent question - software's due in 3 days time... In
Java, is there any way to get a JComponent to react to all keypresses?
ie:

this.getInputMap().put(**any key press**, "doSomething"); // KeyStroke.*
this.getActionMap().put("doSomething", myAction);

Thanks

I'll tip the answer :)

Seb Maynard
Answer  
There is no answer at this time.

Comments  
Subject: Re: Java action listeners
From: bugloaf-ga on 30 Jun 2005 11:29 PDT
 
Instead of using input maps and action maps, add a key listener:

this.addKeyListener(new KeyListener() {
   public void keyPressed(KeyEvent e) { /* do something */ }
   public void keyReleased(KeyEvent e) { /* do something */ }
   public void keyTyped(KeyEvent e) { /* do something */ }
});
Subject: Re: Java action listeners
From: sebmaynard-ga on 30 Jun 2005 13:44 PDT
 
you can't add a key listener to components which don't have a valid
text input field. For example, if i want to implement an input map or
action map on a JPanel, doing this with KeyListeners does nothing...

In the end, i just did a for loop for all of the keys from 0x00 to
0xFF creating actionMaps for each... seemed to work ok :)

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy