Zayne Zayne - 21 days ago 6
Java Question

How to store the filename of an Icon as a String?

So let's say I have some Icon:

Icon something = new ImageIcon("somefile.png");


And I want to store that
somefile.png
in some Strings. How do I do that?

Obviously I can not do
Icon.toString()
or cast so I am kind of stumped by what I am sure it has a simple solution.

Thanks!

Answer

As you see here : http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/swing/ImageIcon.java

The filename goes directly to the description-Field what is used in the toString(). Try

String filename = something + "";

What indirectly calls the .toString().