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 :
16_zoom_pan=/my/project/icon/bat.png 16_mapcontext_enable=/my/project/icon/openegg.png 16_mapcontext_disable=/my/project/icon/egg.png 16_style=/my/project/icon/balloons.png ...
Once the file is ready, load it once at startup in the IconBundle :
ResourceBundle bundle = ResourceBundle.getBundle( path_to_new_bundle ); IconBundle.getResource().setBundle( bundle );
nothing simpler :
ImageIcon img = IconBundle.getResource().getIcon("maplayer_visible");