Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

Getting KeyEvent from JLabel

Thread view: 
larth - 16 May 2005 10:34 GMT
Hi,

how can I subclass the JLabel to have it produce KeyEvents? I have an
image being displayed using a JLabel and would like to receive
KeyEvents when it is in focus. Or do I need to create a new class for
this?

Thanks.
Lars
Michael Rauscher - 16 May 2005 19:20 GMT
larth schrieb:
> Hi,
>
> how can I subclass the JLabel to have it produce KeyEvents? I have an
> image being displayed using a JLabel and would like to receive
> KeyEvents when it is in focus. Or do I need to create a new class for
> this?

<api>
A display area for a short text string or an image, or both. A label
does not react to input events. As a result, it cannot get the keyboard
focus.
</api>

A quick & dirty workaround would be to call setFocusable(true) on the
label. But I'd not rely on this and create a new subclass of JComponent.

Extending JLabel would be (IMHO) wrong, because the new subclass is-a
JLabel and a JLabel is specified to not react to input events.

Bye
Michael
larth - 16 May 2005 22:46 GMT
"A quick & dirty workaround would be to call setFocusable(true) on the
label. But I'd not rely on this and create a new subclass of
JComponent."

I did try this before. Seems like I have to do this the proper way -
thanks!

Regards,
Lars


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.