Solved

catch child compent's key events from container?

Posted on 2002-06-13
4
203 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 100 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 91
Android studio getdrawable(int) is deprecated 4 86
Spring Framework HTTPSession management 1 36
servlet filter example 37 63
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

809 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