• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel - Receiving Focus  RSS feed

 
simon keillor
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can a JLabel use the focus listener? I have an application where images (JLabels) can be moved around a JLayeredPane. I want to know when a particular label has been clicked on, so it's colour can be changed showing which one is currently selected.

I can do it in the mousePressed event but need to change the colour back when something else is clicked on.

Thanks for your help

Simon
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First line of the JLabel javadoc :

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.

Use a JButton instead.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!