All gui swing classes uses the IconBundle class to get there icons. This class is managing ImageIcons to avoid having two times the same image loaded in memory, if the image has allready been loaded it will return you the same reference.
Isn't it a little heavy to load images and images in memory like this?
Don't worry, this class use weakreferences for ImageIcons, so they are remove by the Garbage Collector when no one uses them.
I consider icons as not important and should never block the program, that's why the IconBundle class will never return errors, in the worst case (can not fine the image) it will return a 1x1 transparant ImageIcon.
make a property file :
- You can find the keys in the default file :
- You don't have to replace all keys, if a key if missing in your list the
IconBundle class will go find it in the default icon set.
- To add icons just add your own keys in the file, the IconBundle class
will handle them for you.
Once the file is ready, load it once at startup in the IconBundle :
Getting an icon
nothing simpler :