1

I have a Java Swing application with a JFrame containing a JLabel containing an ImageIcon. I want to monitor the mouse entering/exiting the ImageIcon.

For now I use the addMouseListener method of JLabel but the event Entered & Exited are thrown only when I enter/exit the application's window, not the ImageIcon.

I see no addMouseListener method for ImageIcon.

How can I do this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
IggY
  • 3,005
  • 4
  • 29
  • 54
  • 2
    Probably the `JLabel` is stretched to fill the whole `JFrame` ,that's why `mouseListener` is activated when the mouse enters the `JFrame`. ***[This](http://stackoverflow.com/questions/14548808/scale-the-imageicon-automatically-to-label-size)*** post may help you to fix it. – Extreme Coders May 10 '13 at 05:13
  • 1) Is there text in the label? 2) What layout & constraint.. For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson May 10 '13 at 05:14
  • Take a look at **[this](http://stackoverflow.com/questions/15871530/java-imageicons-and-actioin-listeners/15871783#15871783)** which demonstrates a method of detecting mouse over on images based on the image's pixel alpha levels – MadProgrammer May 10 '13 at 05:19
  • See also [this answer](http://stackoverflow.com/a/7181197/418556) for possible solutions to the problem referenced by @ExtremeCoders – Andrew Thompson May 10 '13 at 05:19
  • 1
    @AndrewThompson Yeah, you caught me showing off ;) – MadProgrammer May 10 '13 at 05:22

1 Answers1

1

I have a Java Swing application with a JFrame containing a JLabel containing an ImageIcon. I want to monitor the mouse entering/exiting the ImageIcon.

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319