Google

Tuesday, March 11, 2008

How to change Application Icon and create Jar deployment using Netbeans 6


1. How to change application icon in Netbeans


Create a folder inside the main project folder. Call it 'lib'.
Put your icon in this 'lib' folder, eg, myicon.jpg. Make sure it is in the highest project directory.
For example, if your project is called Myapplication, then create the 'lib' directory inside Myapplication folder. Note that this 'lib' folder is not the same as the 'lib' folder in the 'dist'
directory described below.

Then, insert this code in red inside the FrameView.java code:

import java.awt.Toolkit;

public class DesktopApplication1View extends FrameView {

public DesktopApplication1View(SingleFrameApplication app) {
super(app);
Toolkit kit = Toolkit.getDefaultToolkit();
Image frameIcon = kit.getImage("lib\\myicon.jpg");
this.getFrame().setIconImage(frameIcon);
initComponents();




2. How to create jar deployment package
Then build your jar package. It will be in the 'dist' folder. It will contain the following:

mynewapplication.jar
lib

lib is a folder, it will contain all the dependency libraries. Next, copy the myicon.jpg icon into
this lib folder. This 'lib' folder is automatically generated and it is not the same 'lib' folder as the one we manually created above.

[Optional] Create a batch file called run.bat and put it inside the dist folder. the run.bat should have this line:

java -jar mynewapplication.jar

Now your dist folder contains 2 files and 1 folder:

1. run.bat
2. mynewapplication.jar
3. lib


The run.bat file is optional. Double clicking the jar file will also execute it. There is no need open a command line to call java -jar ...

To deploy your software, just zip the dist folder and distribute it.

Alternatively, use my ExeIntegrator 1.1 to create a standalone exe file.