Solved

catch child compent's key events from container?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 78
changeXy challenge 13 58
wordappend challenge 8 88
Which is the latest version of Apache Tomcatl 3 36
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now