+ 1
How can I change an image inside a jLabel just when the mouse is over it??
I use NetBeans 8.1 if it's useful. I put an image on a label with a click event (is a close button), but I want it to change color to red or change the image (the same image to red) only when I mouse over the label (the image ) the case is that I can't find a way to do it, I only know ways to do it for buttons and panels, but not for images. Help me please.
4 Answers
+ 2
Denise RoĂberg Good, I'll try it, thank you man ;)
+ 1
Hello Hyst1k
You need a mouse listener.
I think this tutorial helps you:
https://www.tutorialspoint.com/how-can-we-detect-an-event-when-the-mouse-moves-over-any-component-in-java
+ 1
Hyst1k
For example:
ImageIcon icon = new ImageIcon("yourFile");
yourLabel setIcon(icon);
about ImageIcon:
https://docs.oracle.com/javase/8/docs/api/javax/swing/ImageIcon.html
0
Denise RoĂberg Oh Thanks!!
Does it works with Images??