Knowledge Base

Notice Information in this article applies to Excelsior JET version 2.5 and above.

SUMMARY

A JET-compiled executable can be associated with an icon that will be displayed in the application’s shortcut and title bar. For non-GUI applications, it is sufficient to specify a conventional Windows .ico file at compile time. To have a custom icon displayed in the title bar of an AWT/Swing or SWT application, it is also necessary to modify Java source code. By default the respective standard icons are used.

Source files and build/run scripts for this article may be found in the Supplemental Downloads section. If you are using Excelsior JET version prior to 4.5, refer to the samples/BeforeJET4.5 folder, else use samples/FromJET4.5 folder.

DETAILS

Shortcut icon

A shortcut icon is a standard Windows icon file bound to the executable. It is used, in particular, when you place a shortcut to that executable on your desktop or add it to the Start Menu. That icon is also displayed in the application’s console title bar, provided your app has a console.

It is very easy to associate a Windows icon file with the resulting EXE file using the JET Control Panel. On the Appearance page, type the full path of the desired .ico file in the Icon field, or click Browse to select the icon file using a conventional file dialog. /For JET 4.0 and below the respective controls are placed on Resources page./

If you do not use the JET Control Panel, add the .ico file to the project using the !module directive:

    !module myico.ico

Title bar icon: Swing/AWT application

To display your own icon in the title bar of a Swing/AWT window instead of the standard Java icon, use the method javax.swing.JFrame.setIconImage().

For example, if the icon image is stored as "./images/myico.gif" in one of the application’s jar files, use code similar to the following:

      URL iconURL = ClassLoader.getSystemResource("images/myico.gif");
      ImageIcon ico = new ImageIcon(iconURL); 
      frame.setIconImage(ico.getImage());
     

The icon image file must be accessible via CLASSPATH at run time, or placed in a jar bound to the executable (see below).

Title bar icon: SWT application

To display a custom icon in the title bar of an SWT window, call the method org.eclipse.swt.widgets.Shell.setImage().

For example, if the icon image is stored as "./images/myico.gif" in one of the application’s jar files, use code such as the following:

     URL iconURL = ClassLoader.getSystemResource("images/myico.gif");
     Image icon = new Image(display, iconURL.openStream());
     shell.setImage(icon);
     

The icon image file must be accessible via CLASSPATH at run time, or placed in a jar packed into the executable (see below).

Resource packing

If the icon image resides in a jar file, you can pack resources from that jar into the compiled executable. This way, the resulting executable will include the associated icon and you do not have to worry about classpath. Resource packing is controlled through the Classpath page of the JET Control Panel and PACK equation of jc command line compiler. /For JET 4.1 and below resource packing was controlled through the Resource page./

REFERENCES

  1. Excelsior JET User’s Guide: https://www.excelsior-usa.com/doc/jet/jetw.html

SUPPLEMENTAL DOWNLOADS

Article ID: 3
Last Revised On: 07-Jul-2006