If you just put a System.out.println(label.getIcon().toString())
, you will get something like, this
file:/C:/NetBeansProjects/StackOverflow/build/classes/resources/stackoverflow5.png
As you can see, that will not match your case.
You may want to do something like this, to get just the file name
String iconfilename = label.getIcon().toString();
String fileName = iconfilename.substring(iconfilename.lastIndexOf("/" ) + 1);
System.out.println(fileName);
// output
stackoverflow5.png
Then just check against the file name.
if ("stackoverflow5.png".equals(fileName)) {
do something
}