Anas
Anas

Reputation: 23

Display icons on form in java

I am trying to write a java program, where i can set the icon of a form with my own gif file. The problem is , when i run the program from IDE it runs ok, but when i try to run it from the dist folder clicking the jar file, my icon disappears and default java cup icon is show. How can i solve this problem ?

I am doing something like this:

   IDE ide=new IDE();
   ide.setIconImage(Toolkit.getDefaultToolkit().getImage("edited.gif"));
   ide.setVisible(true);

And my gif file is in the project folder. Say my project name is X. So i put the gif file in X folder.

Upvotes: 2

Views: 396

Answers (1)

Boro
Boro

Reputation: 7943

So the thing is that you have to also copy the image to the dist folder next to your jar. And it will work fine.

To save me time remember to do it in NetBeans I edit the build.xml file and the IDE does that for me automatically. Just put the below code just over the </project> tag. And I would recommend to have always all images in a certain folder in my can it is images folder.

<!-- copy data & images folders' contents to dist folder on build. -->
    <target name="-post-jar" description="Copying Images">
        <property name="images.dir" value="${dist.dir}/images" />
        <property name="data.dir" value="${dist.dir}/data" />

        <copy todir="${images.dir}">
            <fileset dir="./images" />
        </copy>
        <echo level="info" message="Images folder content was copied."/>

        <copy todir="${data.dir}">
            <fileset dir="./data" />
        </copy>
        <echo level="info" message="Data folder content was copied."/>
    </target>

Upvotes: 2

Related Questions