Friday, June 29, 2007

HOWTO: set the title bar icon for a JAVA Swing Application

Overview
To help polish a JAVA application, it is always nice to have a custom icon that shows up in the left corner of the title bar and in the task list. To add this is simple.

Technique
Say you have a project that is using a package of jliststriping and in your jliststriping directory, you have an icon called a3.JPG. Here is how you would do it..

java.net.URL imgURL = JListStripingForm.class.getResource(
"/jliststriping/a3.JPG"
);
if (imgURL != null) {
this.setIconImage(new ImageIcon(imgURL,"Icon").getImage());
} // end-if
It is done this way so that you can load the icon from a JAR file.

Final Thoughts
This will help add a little polish to your program.

6 comments:

Anonymous said...

BY: MAHASONA2001
Glad to make the first comment..
Thanks for your precious help man. I was searching for this, and finally found. THANK YOU VERY MUCH.
By the way "JListStripingForm" means the name of the form....
:-D

Anonymous said...

Glad to make the first comment..
Thanks for your precious help man. I was searching for this, and finally found. THANK YOU VERY MUCH.
By the way "JListStripingForm" means the name of the form....
:-D

Anonymous said...

Glad to make the first comment..
Thanks for your precious help man. I was searching for this, and finally found. THANK YOU VERY MUCH.
By the way "JListStripingForm" means the name of the form....
:-D

Anonymous said...

Thanks a lot.
Works perfectly.

Anonymous said...

Thanks a lot.
Works perfectly.

Anonymous said...

Thanks a lot.
Works perfectly.