Gif files placed in a jar file. Help to get these files.

I have placed all the gif files in a jar file.
added the gif.jar to the project in the required libraries of project properties.
In the toolbar class I gave this.
JButton btnNew = new JButton(new ImageIcon("new.gif"));
and was expecting it to shpw the icon but I didn't get it?
Can I place the gifs in a jar file.
What else can I change/check to see the icons?
Thanks.

Ok, lets try it this way:
I have small samples on my server, which solve your
problem. If you look at them, you can see
how it works from a working example as starting point.
CAUTION: This one ONLY works, if you have
selected a JVM 1.3x.
[ It doesnt work for jvm 1.4, because it references
the main class in unnamed space. Thanks SUN ! -
why was this needed ??? (security I guess) ]
Steps:
1) goto http://www.snowraver.org/java/index.htm
2) download the "jarcreator.jar" example
[ There is a small link "Download JarCreator.jar -
although you also can start it as WebStart application
if you click on the big button on that homepage ]
3)
The jar file contains the classes as well as the
java source files and 2 gif pictures, which are
loaded using the above explained method
"LoadImageIcon"
You can see how it works from that example.
For extracting the source files, you can rename it
and give it the ending .zip on windows, then
you can extract all files using WinZip )
The main class (called Idefix above) must be outside
any package, that is, there must not be
a package statement at the beginning.
Some notes:
If you are working without jar file, the method
can return an ImageIcon object, although it
couldnt find it. In this case, the width and length
of that ImageIcon are zero.
Usually no problem. But imagine you use the
image icon for a tiled background. You loop
would be endless then.
It's a good idea to inspect the width of an imageicon
for checking its greater zero.

Similar Messages

  • I was messing with the computer, not sure what i hit but now all my toolbars at the top of the screen are gone? (file, edit, history, tools and my forward and back button). Please help me get these settings back to the way they were?

    My file, edit, view, history, bookmarks, tools, and help buttons at the top of the screen are gone, along with my forward and back button.

    For details of how to restore it, see https://support.mozilla.com/kb/menu+bar+is+missing
    Once the menu bar is restored, you can use the Toolbars entry in the View menu to restore other toolbars such as the navigation toolbar.

  • Gifs placed in a jar file. need help getting them.

    I have placed all the gif files in a jar file.
    added the gif.jar to the project in the required libraries of project properties.
    In the toolbar class I gave this.
    JButton btnNew = new JButton(new ImageIcon("new.gif"));
    and was expecting it to show the icon but I didn't get it?
    Can I place the gifs in a jar file.
    What else can I change/check to see the icons?
    Thanks.

    They are in the same path in the jar file that they were when they were on your disk in the file system. Lets say you have a dir structure
    C:\dir1\dir2\dir3\dir4\file.txt
    and you cd to dir2:
    cd \dir1\dir2
    then you jar dir3:
    jar cvf jar.jar dir3/*.*
    the path to file.txt would still be /dir3/dir4/file.txt inside the jar file.
    do a jar tvf jarfile.jar and take a look.

  • Unable to read a .gif file from a jar

    I have made an application which requires some .gif images.
    I packed all the classes and .gif's in a jar file.
    I have used no package statement in files, all are in one folder.
    While retrieving the .gif file from the jar I have used..
    Image img1 = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("Lock.gif"));
    ImageIcon i1=new ImageIcon(img1,"No Users");
    but this does not works and throws nullpointer exception.
    I have also tried getClass().getResource() etc.
    But none of the methods are working..
    Plz. help.
    Nimesh

    Is the class that is loading the image contained in a package? If the resource name does not start with a forward slash, it is interpreted as relative to the package of your class(when doing getClass().getResource())

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • Gif file not found in JAR from Java Application

    Hello Forumers,
    Could some one please explain how to create a JAR file from where I can get a GIF file. I have tried a number of different ways but it allways fails. (I have tried to add the GIF files using the jar command and I have tried to add it using WinZip after the jar is created).
    To isolate the problem I created this very simple program, the program works very well when the gif file resides on the directory from where I run the Application, but when I remove it from the directory it fails. I have tried to put the GIF file in the JAR in a number of different ways but it allways fails. (I have also tried with and without slash before the name of the GIF). I guess the problem is the way I create the JAR file
    import java.io.*;
    public class GifTest
    { public static void main(String args[])
    { InputStream in = GifTest.class.getResourceAsStream("/open.gif");
    if (in==null)
    System.out.println("Null returned");
    else
    System.out.println("OK");
    Any Hints appreciated
    /Kjell

    Hi,
    here is a small application using my own class GetImageIcon.
    Normally I have this "help-class" in a utility-package to use it from all my projects without copying. For this example I copied the code in the test application. Feel free to use the code of the class like you want. For me it works fine.
    Do the following:
    1. Create a folder called /meta-inf under the folder where the class-files are. Use a text-editor and create a file saved as "manifest.mf".
    manifest.mf tells the jar-file which is the main-class from where the application will start when double-clicked.
    It only has to contain one line:
    Main-Class: GifTest
    2. Compile and create the jar file. I made a bat-file containing:
    javac -verbose GifTest.java
    %pause
    REM Create Jar-File
    jar cmf meta-inf/manifest.mf GifTest.jar *.class *.gif
    REM Show Table of Content of the Jar-File
    jar tf GifTest.jar
    %pause
    So you can see what's in the jar-file.
    3. When you double-click on the jar-file the application is executed. So it is easier to use for the users. They don't have to type in anything on the command-line. You can deploy this jar-file to any client and run it. The only thing you have to do, is to install the JRE on the clients.
    I develop with JDK 1.3.1 and JRE 1.3.1 is installed on the clients of the company I work for.
    //Begin of the code
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.util.jar.*;
    public class GifTest extends JFrame
            protected JLabel m_title;
            protected ImageIcon m_image;
            static File file;
            //You have to define the name of the jar-file
            static String jarFile = "GifTest.jar";
            //Instance of the class GetImageIcon
            protected GetImageIcon gii = new GetImageIcon();
            public GifTest()
                    super("GifTest");
                    setSize(400,200);
                    //the name of the image and the name of the jar-file the image resides in
                    m_image = gii.getImageIcon("orb.gif", "GifTest.jar");
                    m_title = new JLabel(null, m_image, SwingConstants.CENTER);
                    getContentPane().add(m_title, BorderLayout.NORTH);
            public static void main(String argv[]) {
                    GifTest frame = new GifTest();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setVisible(true);
    public class GetImageIcon{
    * @param fileName the full qualified name of the file
    * from the root of your application. use a "/" before the
    * fileName, eg. /images/warning.gif
        public ImageIcon getImageIcon(String fileName, String jarName) {
            int counter, c, i = 0;
            byte buffer[];
            JarFile  jfile;
            JarEntry jentry;
            InputStream in;
            ImageIcon m_image;
            try{
                    // Create Jar-File object from JarFile
                    jfile = new JarFile(jarName);
            catch(Exception ex){
                    System.out.println("JarFile-Problem " + "\n" + ex);
                    return null;
            try{
                    // create Jar-Entry object from File-Name in JarFile
                    jentry = jfile.getJarEntry(fileName);
            catch(Exception ex){
                    System.out.println("JarEntry-Problem " + "\n" + ex);
                    return null;
            try{
                    // create InputStream from JarEntry
                    in = jfile.getInputStream(jentry);
            catch(Exception ex){
                    System.out.println("JarEntry-Problem " + "\n" + ex);
                    return null;
            try{
                    //get uncompressed size of entry data in Jar-File and create byte-array with this size
                    buffer = new byte[(int)jentry.getSize()];
                    //write int-value 'c' (casted to byte) with read() and while-loop in byte-Array
                    while((c = in.read()) != -1){
                            buffer[i] = (byte)c;
                            i++;
            catch(Exception ex){
                    System.out.println("in.read()-Problem " + "\n" + ex);
                    return null;
            try{
                    //create ImageIcon with byte-Array 'buffer'
                    m_image = new ImageIcon(buffer);
            catch(Exception ex){
                    System.out.println("ImageIcon-Problem " + "\n" + ex);
                    return null;
            // return the created ImageIcon
            return m_image;
    }

  • To read a gif file from a jar

    I have made an application which requires some .gif images.
    I packed all the classes and .gif's in a jar file.
    I have used no package statement in files, all are in one folder.
    While retrieving the .gif file from the jar I have used..
    Image img1 = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("Lock.gif"));
    ImageIcon i1=new ImageIcon(img1,"No Users");
    but this does not works and throws nullpointer exception.
    I have also tried getClass().getResource() etc.
    But none of the methods are working..
    Plz. help.
    Nimesh

    Hi,
    Use a / with the name of your gif e.g.
    frame().setIconImage((new ImageIcon(getClass().getResource("/myimage.gif")).getImage()));

  • I had made ppt with gif files.however the animations are now working when in keynote. Can u help?

    I had made a PowerPoint presentation and have lots of gif file with animations. But when I opened it with keynote, the gif files don't seem to work. Please help

    The inspectors on your iPad are there but disguised - the 4 icons on the upper right are Styles (brush) - that allows you to modify attributes of a selected object such as color, font, position, etc., it is contextual so will vary depending on the object selected; Insertion ("+") - this allow you to insert shapes, tables, charts and media (images and movies located in the Photos library); Tools (wrench) - this menu allow access to transition & builds, sharing and printing, a find feature, your presenter notes, some advance settings, and MOST IMPORTANT OF ALL - the HELP File where you can learn how to use your Keynote application.
    The Help file and the Getting Started presentation are the best way to learn how your Keynote works.
    Good Luck,

  • Gif - file help: i don't want to read the gif each time from the file.....

    Hello there guys,
    i'm making a game and therefor i need to read a gif file like 20 times.
    i don't want my program to read the gif each time from the file, but only once.
    so i load it into an image or something?
    cuz opening the gif 20 times from my hard disk is a lot of time loss....
    opening it once and store it is much more efficient
    thx in advance
    plz help me out, cuz i don't really know how to do it.
    (in Delphi it's easy, but Java......)
    greetz,
    SpeciesXX
    Ramon Ribbe

    yes, it works, i used this code, thx man
    void button1_ActionPerformed(java.awt.event.ActionEvent event)
              ImageIcon image = new ImageIcon("f:/a.gif");          
              JLabel label = new JLabel();          
              label.setIcon(image);                    
              this.getContentPane().add(label);
              label.setBounds(10,10,100,100);
    and there i see my image :-)
    but 1 more thing, should i display all those blocks (images) on an applet, or should i use something else? (like what??)
    a sort of frame?
    because later on i have the field where all the blocks are in, and i have an area surrounding it, displaying all kinda information about the game, like how many lives remaining....
    can i put 2 applets in eachother? like applet1 is the parent of applet2?
    or should i use something else?
    plz help me, cuz java is kinda new to me i see....
    in delphi i just used 2 forms, form 1 with the blocks, form2 with the rest of info, and also being the parent of form1
    thx again, soon i can help ya guys too, i hope..
    (im learning java at school, but way too slow and to ez)
    Ramon

  • GIF files not loading from jar in Netscape

    Hi,
    I have a jar file that contains my applet code(class files) and a bunch of gif files. I load the image using the URL returned from getCodeBase() method. The images load fine in Explorer but they do not show up in Netscape. The class files and gif files are not in separate directories and getCodeBase is returning the correct URL of my server(Example: http://www.myserver.com). Does anyone know how to fix this? I also noticed that download time did not improve on either browser when I bundled all the gif file in the jar rather than place them outside the jar file. Isn't bundling them in the jar supposed to save multiple requests back to the server to get the gifs and thus reduce download time? Thanks in advance.

    There the sample from Netscape: http://developer.netscape.com/docs/technote/java/getresource/getresource.html#classloader

  • Please help--I am trying to open a Gif file and can't manage it.  I was told to try iPhoto.  When I tried to open iPhoto, I could not without first upgrading it.  After doing this it still will not open.  Just this week I upgraded to Yosemite, I have

    Please help,  I am trying to open a GIF file and I am told it may be damaged or use a file format that preview does not recognize.  Is there another path I can take to be successful?      Many Thanks    John

    Please log out or restart the computer and try again.

  • Jar file and gif file

    why jar file cant load the .gif file? is it need to specify the directory for the .gif file in jar? when i run my applet, that can't load the picture, what is the problem? below is my code:
    public static final ImageIcon ICON_FOLDER =new ImageIcon("folder.gif");
    for (int i=0; i<v.size(); i++) {
                   FileNode nd = (FileNode)v.elementAt(i);
                   IconData idata = new IconData(DirTree.ICON_FOLDER,
                        DirTree.ICON_EXPANDEDFOLDER, nd);
                   DefaultMutableTreeNode node = new
                        DefaultMutableTreeNode(idata);
                   parent.add(node);
                   if (nd.hasSubDirs())
                        node.add(new DefaultMutableTreeNode(
                             new Boolean(true) ));
              }

    if the image is in your jar file,maybe you can use:
    public static final ImageIcon ICON_FOLDER =new ImageIcon(this.class.getResource("folder.gif"));
    variable "this" stands for your class which extends Applet or JApplet
    ...I'm not sure

  • Iconic buttons in design time ... Is there any way to take their icons from the jar or at least from gif files?

    I've put my button icons in a signed gif, and they work fine at runtime.
    The problem is at design time, I can't get to see their icons properly.
    I have to convert the gifs to ico and place them in a folder referenced by the old UI_ICON registry variable.
    Also, as the gifs are 16x16, they are cropped in design time, because I see them as if they where stretched to 32x32 size.
    At least it would be enough if I could place the gifs directly somewhere, without converting to ico.
    It seems as if oracle had not put any development work in the builder, which is like a direct port from the 6i c/s version.

    Since you didn't mention exactly which Forms version you are using, I will guess and assume it is one of the many versions after 6.0.8.  The Forms Builder 9.x+ supports ico, jpg, and gif files.  It will not however read them from a jar.  Therefore, you will need to extract them into a directory as defined by UI_ICON.  Also, the files will need to be of the same type (gif, jpg, ico).  Mixing formats is not recommended or supported.  The format you choose can be defined in UI_ICON_EXTENSION
    So for example in your Registry you might have something like this:
    UI_ICON = C:\myImagesDirectory
    UI_ICON_EXTENSION = gif
    Since "gif" is the default, you do not need to set this if using "gif" files.

  • Animated .gif file correction and image ready help.

    Hi,
    I have an animated gif created in an early verison of Image Ready & Photoshop. I need to make some changes. I have two problems.
    A: Can't figure how to do it in the current version of Photoshop.
    B: Open in the old image ready version, can't find the Layers pallet. I turn it on and off and it doesn't appear.
    Trying to recreate a rotating .gif file any pointers or how to's?
    Thanks,
    John

    You didn't say which version of ImageReady, but cs5 should open
    most animated gifs from ImageReady and show the frames in the
    Window>Animation panel. Some may not work right depending on
    how old the version of ImageReady was that created them.
    (you may have to resave the animation in ImageReady as a psd file)
    In ImageReady try Window>Workspace>Reset Palette Locations and the layers
    palette should be visible.
    In ImageReady, in the actions palette, are several actions to rotate (spin) images.
    MTSTUNER

  • Unable to access gif files from the server

    hi all,
    i have successfully signed an applet and it is loading in the client system also. in that applet, i instantiated a jbutton as given below:
    JButton jb = new JButton(new ImageIcon("http://192.168.91.154:8080/success/set.gif"));
    but the icon din appear and a blank button appears, even when accessed from the server system.
    if i give the exact path like c:/blazix/webfiles/success/ set.gif, the icon is coming in the server system but not in other systems. i tried without port no also but in vain. pl solve my problem. what i need is how to
    specify the path of the file[any file] which is present in server.
    or if i put all the gif files in the jar file, can i access the gif files present in the jar file [set for archive] ? if i can, give me the soln for accessing the gif file present in the jar file, so that i need not access the server to get the gif files.(i.e) how to specify the path of the gif files present in the jar file?
    i ve one more doubt. the jni library file shld be in the server, and the client has to access the library in the server. i think the applet loaded in the client ll search for the library in the local m/c only . how to make the applet to search for library in the server??
    i feel only by using rmi we can solve this problem. am i correct? if so i feel that an appln or applet running in the server shld access the jni library, and the applet in the client side should communicate with this server appln using rmi to get the data.is it correct? is there
    anyother way?
    i appreciate your help in this regard. thanks in advance. bye, padmanbhan.

    Better information on what you are doing with JNI might help you get an answer.
    If you have some server process that needs to use JNI, then I would code a servlet to call, instead of using RMI to ge there.
    Depending on your environment, and the target audiences environment, RMI may just cause you a lot of grief. Firewalls etc, get in the way of RMI connections and force security holes to be opened in order to work.
    If you use a servlet, then traffic to your server process is done via standard http calls, which will already be enabled, because your app runs in a browser.
    If ther data requirements are heavy duty, your server could always send an XML stream to the client, which would allow you to describe complex data to the client.
    Running JNI stuff from the client directly means a lot of local infrastructure to run your app. The code you want to run, the JNI library ....
    If what you have is really an application, but want the convenience of starting it from a browser, look at Java WebStart. Then you can distribute an application via the browser, and WebStart will worry about the deployment issues for you.
    In Summary:
    Stay away from RMI from applets if you can help it.
    If you really have an App, then try WebStart to manage the distribution issues for you.

Maybe you are looking for