I have written several SWING programs that I use to do various utility tasks. All of these use icon size *.gif graphics, including my personal icon 'stamp' in the title line of the program. For instance, one of my programs can create a text document of a branch of the file system using a JFileChooser. To start these, I have created *.bat files with MS_Shortcuts on my NT4 desktop. My question is, is there a way of embedding an icon in the Java application so that when I create an MS_Shortcut, it uses my icon rather than the NT4 default, (looks like a window with a gear).
i can offer some suggestions (for what they're worth):
1) if you are placing *.bat files on the desktop as shortcuts, nothing you do in your java programs will impact the icons shown on the desktop.
if you invoke your code using .bat files, and you want custom icons, then you can always either
(a) edit the properties of the shortcut and change the icon, or
(b) use .pif or .lnk files containing appropriate references
2) if you want to STOP using .bat files, and launch with java, you can still manually create desktop shortcuts with the icons you prefer. If you installed the java SDK, you can probably drag-n-drop your jar onto your desktop and run it straight-away (...once you chg the icon of course:-)
3) intermediate level: windows desktop can do web-style launch of your app, depending upon how you have packaged it ... but this has nothing to do with the desktop icon, so i'll skip the blab
4) FINALLY, if you want something more windows-ease, then you'll need to work with windows internals to create some kind of launcher for your apps. (.exe s can have associated icons that will get automatically displayed in shortcuts)
if you'd like to see an example of that, have a look under the hood at the jEdit launcher. The launcher is a COM component written in C/C++. Although JEdit is a java-based editor (and a fine one too!), the win launcher is an .EXE file (the install program updates the windows registry as well).
But I'm guessing you don't wish to do something that elaborate for the level of compatibility you're after...
anyway, hope one of these suggestions is helpful...
The way Windows programs work is that you embed the graphic in a special Windows-specific "resource", link the resource into your (Windows-specific) .exe, where the Windows runtime detects and uses it from the Windows .exe.
You can't do this in Java.
Windows "shortcuts" (.lnk files), however, are actually something completely different. They are COM/ActiveX objects ("monikers", specifically) that the Windows desktop knows how to interpret ... and to which you can assign any (valid Windows!) icon you want, just by right-clicking on it and changing its properties.
So your best bet is probably indeed to: 1. Write a simple .bat file that does what you want 2. Create a shortcut (.lnk) to the bat file 3. Assign whatever icon you want to the shortcut
Hope that helps .. PSM
Paul M. Santa Maria, SCJP
Joined: Jul 14, 2002
Clio and Paul, Thank you both for your replies. I will probably just replace the default *.bat file icons with my own choice. I was just hoping for a more elegant solution.