SetIcon Class
[Previous] [Main] [Next]

SetIcon Class

Setting the icon on a JFrame is relatively easy. The only difficult part if finding the icon. This is done using a static class called SetIcon View This class does two major things.

A) It checks to see if you are running from a jar and uses a classloader if you are. If you are not the image you specific is found in the users file system. All images are expected to be in a folder called "images" which is under the home folder for your application.

B) It handles internationalization. If your program will run in different locales and you want different gif files for different locales, place them in folders under the images folder. Locales are designated with a language (tow lower case letters) and a country (two uppercase letters). If you have a special gif for people in Mexico, you would place this gif in a folder called "images/es[MX." The system would check there first. If if cannot find the gif, it tries in "images/es". If this fails, if looks in the images folder.

Here is the code that calls the SetIcon class: JxFrame Example - Replace coffee cup icon on frame

There are two ways to call SetIcon

SetIcon.setFrameIcon(frame, gifName);
SetIcon.setFrameIcon(frame, gifName, locale);

If you don't pass in a locale, it presumes en_US (english - US version).