![]() |
|
|
| 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 |
|
| There is no answer at this time. |
|
| 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 :) |
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 Home - Answers FAQ - Terms of Service - Privacy Policy |