Results 1 to 5 of 5
- 08-06-2011, 07:14 PM #1
Event Collision (What I call it) Problem.
For an example if you have a program with one JPanel that is changing to "Blue" when klicking at the "B" button & "Red" when klicking at the "R" button. If you have a JButton (Or any kind of button) at the side of it, when you press it, with an ActionListener, the KeyListener stoppes working.
The KeyListener is at the "Frame" object, wich is pretty much just a normal JFrame.
Your problem is a common KeyListener problem: KeyListeners can only work when the component that they've been added to have the focus. When you click on a button, whatever had the focus before loses it, and this causes the key listener to stop functioning.
A good solution for this is to use key bindings instead. Please check out the tutorials for the details on how to use these: Key Bindings Tutorial
- 08-06-2011, 09:00 PM #3
Is there any possible way to reset the focus of the window back?
Why not simply use Key Bindings as suggested?
- 08-06-2011, 09:10 PM #5
- By counterfox in forum AWT / SwingReplies: 0Last Post: 01-28-2011, 12:48 AM
- By Chetans in forum Java GamingReplies: 3Last Post: 03-15-2010, 11:24 PM
- By kirzo in forum New To JavaReplies: 3Last Post: 07-11-2009, 12:23 PM
- By prabhurangan in forum Web FrameworksReplies: 0Last Post: 07-07-2008, 07:10 AM
- By ahdus in forum Java AppletsReplies: 1Last Post: 11-17-2007, 06:24 PM