1 Reply Latest reply: Mar 30, 2010 12:18 PM by 843804 RSS

    Problem in loading images.

    843804
      I am doing a project. I am creating a jar file which i can execute anywhere. I have some 30 class files in my project.
      i am creating jar file by this command
      jar cfm IBC.jar *
      i have not specified manifest file and then after i am modifying manifest file as
      Main-Class: Splashscreen
      where spashscreen is my main class.

      i have also added image files in my project.
      and jar file contains images.
      i have created the project using netbeans.
      when i build it creates a jar file also in dist directory.
      But when i try executing the file which i created manually then it gets executed but i cannot view the images on my forms.
      also the class files and image files are in src directory. When i place jar file in src directory and execute it shows images on form but when i change the directory it does not. What can be the problem. Same problem is with netbeans generated file also. Please help me!
        • 1. Re: Problem in loading images.
          843804
          Hello there,
          To load images to Jars I recommend to you that you follow these methods
          JLabel label = new JLabel(); 
          ClassLoader cldr = this.getClass().getClassLoader();
          java.net.URL imgUrl = cldr.getResource(" -- img dir -- ");
          ImageIcon img = new ImageIcon(imUrl); 
          
          label.setIcon(img); 
          In this case the Jars files would make sure that it loads this images.
          Regards,