+ 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.

2nd May 2020, 12:38 AM
Hyst1k
Hyst1k - avatar
4 Answers
+ 2
Denise Roßberg Good, I'll try it, thank you man ;)
2nd May 2020, 6:57 PM
Hyst1k
Hyst1k - avatar
2nd May 2020, 6:15 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
2nd May 2020, 6:49 PM
Denise Roßberg
Denise Roßberg - avatar
0
Denise Roßberg Oh Thanks!! Does it works with Images??
2nd May 2020, 6:33 PM
Hyst1k
Hyst1k - avatar