Solved

catch child compent's key events from container?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
more than one jdk and one jre 1 50
throw exception 21 58
Java basic valueOf question 1 29
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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