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