Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

catch child compent's key events from container?

Posted on 2002-06-13
4
Medium Priority
?
230 Views
Last Modified: 2010-03-31
Hi,
   I have a JPanel which contain some image JLabels.
How can I add a key listener to JPanel that catch
key events even JLabels
is in focus.

Thanks.
Sean
0
Comment
Question by:xzhang4
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 7076115
According to the javadoc, JLabel cannot get the keyboard focus. Do you have some sample code that doesn't work as you had expected?

Jim
0
 

Author Comment

by:xzhang4
ID: 7076307
OK.  I am wrong.   How about JPanel contain some JButtons.
Thanks.
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 7076781
Try getting the input map as follows:

InputMap map = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

Add add your input action to this map.
0
 
LVL 92

Expert Comment

by:objects
ID: 7082828
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question