Jar files, imageIcon and image

I am building a little POP3 client and I am making the GUI with Swing.
I have a problem:
i would like to put all my classes into a jar file but so i can't load images like the imageIcon and the image for my buttons.
I have a directory with my class files and a subdirectory with the images. All classes are a part of a my own package. And so I have:
$\>RootDirectory\ [here is all class file and subdirectories]
$\>Rootdirectory\img [here is all images i need]
to make the jar file i use jar cvf myapp.jar RootDirectory
but when i lounch the application i can't see images.
I really hope thet anybody can help me!
sorry my bad english

Use the getResource(String string ) of Class: For example
ImageIcon myIcon = new javax.swing.ImageIcon(getClass().getResource("/images/VerticalRuler.gif"))
The images dir in the above example is a subdir of app's working directory. See Class API for details
Hope that helps
DB

Similar Messages

  • How to delete a jar file after loading image files from it

    Hi,
    How can I delete a jar file after some image files have been loaded? For example, say, I have "a.jar" which contains an image "a.gif" in the root directory of the c drive. I would like to get the image size and then delete the jar file. Here is the code snippet:
        URL url = new URL("jar:file:/C:\\a.jar!/a.gif");
        Icon icon = new ImageIcon(url);
        System.out.println("icon size ? " + icon.getIconHeight());
        File file = new File("c:\\a.jar");
        while(file.exists())
            file.delete();
            try
                Thread.sleep(100);
            catch (InterruptedException ignored)
        System.out.println("file deleted.");I get the image size correctly but just can not delete the jar file. Apparently the file handle is not released, but how to close it? Any hint will be appreciated.
    Justin Jan

    I am sure the URLConnection.defaultUseCaches is set before it is connected otherwise I should catch an IllegalStateException on conn.setUseCaches(false).
            try
                URL url = new URL("jar:file:/C:\\a.jar!/a.gif");           
             URLConnection conn = url.openConnection();
               conn.setDefaultUseCaches(false);
             conn.setUseCaches(false);
                Icon icon = new ImageIcon(url);
                System.out.println("icon size ? " + icon.getIconHeight());
                url.openConnection().getInputStream().close();
                System.gc();
             System.runFinalization();
                File file = new File("c:\\a.jar");
                while (file.exists())
                    file.delete();
                    try
                        Thread.sleep(10);
                    catch (InterruptedException ignored)
                System.out.println("file deleted.");
            catch (Throwable t)
                t.printStackTrace();

  • Jar file not showing images

    Hi
    When I make a runable jar file, my images it not showing if I try it on another computer. I searched the net and most people seems to use URLs instead ImageIO. But that doesnt help me either. Then I get the error message: Uncaught error fetching image:
    java.lang.NullPointerException
    Code is below. I hope someone can tell me what I should do.
        private Show show;
        private final int unit = 32;    // size of the images
    //    private BufferedImage free;
        private Image free;
        private BufferedImage booked;
        private BufferedImage toBeBooked;
        private BufferedImage ableToEdit;
        public TheaterOverview(Show show)
            this.show = show;
    //        try
    //            free = ImageIO.read(new File("src/images/user_alt2.png"));
    //            booked = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user_alt.png"));
    //            toBeBooked = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user.png"));
    //            ableToEdit = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user-yellow.png"));
    //        catch (Exception e)
    //            System.out.println("Not able to read images " + e);
            try
                URL myurl = this.getClass().getResource("images/user_alt2.png");
                Toolkit tk = this.getToolkit();
                free = tk.getImage(myurl);
    //            free = ImageIO.read(new File("images/user_alt2.png"));
                booked = ImageIO.read(new File("images/images/user_alt.png"));
                toBeBooked = ImageIO.read(new File("images/images/user.png"));
                ableToEdit = ImageIO.read(new File("images/images/user-yellow.png"));
            catch (Exception e)
                System.out.println("Not able to read images " + e);
         * The paint method. Checks what the status is of each seat and draws them accordingly.
        public void paint(Graphics g)
            Show show = getShow();
            int numberOfRows = show.getTheater().getNumberOfRows();
            int numberOfSeatsInRow = show.getTheater().getSeatsPerRow();
            for (int i = 0; i < numberOfRows; i++)
                for (int j =0; j < numberOfSeatsInRow; j++)
                    Seat seat = getShow().getRow(i).getSeat(j);
                    if(seat.isAbleToEdit())
                        g.drawImage(ableToEdit, j*unit+1, i*unit+1, null);
                    else if (seat.isBooked())
                        g.drawImage(booked, j*unit+1, i*unit+1, null);
                    else if (!seat.isBooked() && !seat.isSelected())
                        g.drawImage(free, 0, 0, this);
                    else if (seat.isSelected())
                        g.drawImage(toBeBooked, j*unit+1, i*unit+1, null);
        }

    just work on getting one simple image to .jar OK
    e.g. this should .jar OK (after changing image names)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      Image img;
      public void buildGUI()
        try
          java.net.URL url = new java.net.URL(getClass().getResource("Test.gif"), "Test.gif");
          if(url != null) img = javax.imageio.ImageIO.read(url);
        catch(Exception e){}//swallow exception - handled in paintComponent
        JPanel p = new JPanel(){
          public void paintComponent(Graphics g){
            super.paintComponent(g);
            if(img != null) g.drawImage(img,100,100,this);
            else g.drawString("this space for rent",100,100);
        JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.setSize(400,300);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }put the image in the same folder, make .jar, then try the .jar on another pc
    if all OK, change code to locate image file in subfolder, make .jar, then try the .jar on another pc
    if all OK now, modify main program accordingly.
    note: in .jars, capitalization of the image file names counts
    e.g. in my above example, if I change Test.gif to test.gif, the image is not drawn

  • Jar file upload and transport in Java webdynpro

    Hi,
    I wanted to change do small chnage to the existing jar file in webdynpro jave application. I did change the jar file.
    Question: Please let me know how can i include this jar file into existing application back and how the transport happend for the same?
    do we need to copy paste the ne jar file(updated jar file) in local drive where it exists and do little chnage the application will create an activity. then move to test and prd  will that move the jar file as well?
    appreciate your prompt help.
    Thanks
    Rag

    hi rag,
    1) "Like this have couple projects for same application. Under two are Jars, under these two jars i have to update my changed jar. Then the file used in another project.
    I can see other project which is using this jar is seeing in webdynpro explorer.
    But two jar projects are not showing in webdynpro explorer, but they can see through Navigator after i imported into location NWDS."
    here it shows that two are external library files having the jar file in the library folder.
    2) "My request is i have changed the jar file from existing jar project and replaced it in local path where it is currently. but it didnt ask me the activity to deploy the same.
    In this part , im not clear like how you were able to change the jar file without checking out the external lib dc , in the external lib, as i told earlier if it was checked out then activity will not be asked,
    3) "so how do i update JAR file and delpoy into server. and where can i see the JAR file been updated in server? i am how to deploy into server."
    JAR file cannot be deployed directly the way you deploy a DC or Webdyn pro project.
    if you have changed the jar file , just build your webdynpro project that uses this jar file. and deploy the same . The new jar file gets deployed along with your webdynpro project.
    if you want to deploy jar file, then you have to create a wedynpro development component of type j2EE-Server--library .
    Then in Used Dcs add your external lib dcs assembly public part with build time dependency
    go throught this blog you will know more about external jar file and its usage at run time.... and how it is getting deployed to the server.
    https://scn.sap.com/people/bertram.ganz/blog/2008/11/24/how-to-use-external-jar-files-in-web-dynpro-development-components

  • When searching for an image in Finder on iMac, I found hundreds of images of printers !! All sorts of printer images which I certainly haven't loaded on.I went to Finder, File, Find and Image and there they are, hundreds,if not low thousands of them.

    I was searching for an image on my Imac and when I went to Finder,File,Find and then Image, I found hundreds if not early thousand images of printers ! Amazing in one way but I didn't put them on my machine and don't really want them there.Did they come pre-loaded? Can I delete them safely? Thanks

    Almost certainly, no absolutely not once you start deleting stuff like this that you think is not needed, eventually you'll trash something essential and cause yourself a lot of heartache.
    There are numerous files classed as images, some will be temporary files in browser caches, others system files, others your "real" images, others files which are not really images but appear to be.
    The amount of space of what I presume are essentially icons of printers will will be minimal, lets say these images are  5k in size (I guess they are much smaller?) and there are 1,000 of them, thats only 5Mb. No doubt your disk has multiple gigabytes free, eg thousands of times as much free as you'd save by deleting all of them. So you might gain back an extra 0.0001% disk space*. NOt worth the time, let alone the risk, plus then you'll get into a mindset "hmm, I dont think I can possibly need this 23byte file either I'll delete that as well etc, and then "problem......". 
    Where are the images stored? It may be that at some time you were searching for a new printer and these images are from that exercise (though I doubt you looked at thousands?) in which case they are in your browser cache and you can always delete that through the browser, but that space will be overwritten by other images anyway.
    "If it ain't broke, don't fix it" is a motto to work by with computers.
    *( or, if you really do need the (say) 5MB of disk space back because you are running out, this would only be a very temporary solution and that wont have done you any good)

  • HELP!!! Could someone help me with a jar file issue and JRE 1.3 & 1.4

    We had a problem with the last Oracle patch in that it tried to extract from a jar file using the "jar" executable. But the jar executable is not installed on the server where we have JRE 1.4
    On one server, Jar.exe is installed where we have JRE 1.3. Is the jar.exe apart of JRE 1.4? If so, where do I find the jar.exe file? If it's not part of JRE 1.4, what do I need to do to get the jar.exe onto the server where JRE 1.4 is installed?
    Thanks, Carl

    Thanks for your replies.
    I know that a jar file is like a zip file but I'm asking, "Can you download just the jar.exe without downloading the JDK?"
    I keep reading everywhere that you can only get the jar.exe tool if you download the JDK but I can't use JDK(because it is a compiler) on our website here at work.
    Thanks,
    Carl

  • HELP!!! Could someone help me with a jar file issue and JRE 1.3 and JRE 1.4

    We had a problem with the last Oracle patch in that it tried to extract from a jar file using the "jar" executable. But the jar executable is not installed on the server where we have JRE 1.4
    On one server, Jar.exe is installed where we have JRE 1.3. Is the jar.exe apart of JRE 1.4? If so, where do I find the jar.exe file? If it's not part of JRE 1.4, what do I need to do to get the jar.exe onto the server where JRE 1.4 is installed?
    Thanks, Carl

    The jar tool isn't part of the jre but the jdk. You should find it on your server in %ORACLE_HOME%\jdk\bin (seems you use some kind of Windows).

  • 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

  • Weird symbol in file name and images by pixel instead of size?

    i my filenames i sometimes see a weird box with what looks like a script "x". is this some kind of default symbol that indicates i am using a non standard symbol in this file name? it sometimes happens after i drag and drop something say from my desktop to my laptop.
    also, is there any chance of being able to see pixel size of images in a Finder window in addition to or instead of File size?
    Thanks.

    Some things about this.
    1. Ignore the back slash in front of the space.  That's the terminal shell convention for escaping (making significant) special characters that follow the back slash (in this case a space).
    2. A pathname like ~/foo/bar is another shell convention where the tilde is a shorthand for your home directory.
    3. I am not convinced that the weird stuff is not there in the Finder display.  I think it just doesn't show in the Finder's desktop font.
    4. I am going to use your example for the following discussion.  Extrapolate where needed.
    The terminal shows a pathname like /Users/homename/Desktop/_evolute\ tutes, i.e. with some kind of garbage character(s) after tutes.
    In terminal type cp followed by a space and drag that tutes file into the terminal window.  I think it will look something like this (don't hit return yet).
    cp /Users/homename/Desktop/_evolute\ tutes
    Now type a space and add ~/Desktop/foobar on to the end of the line.  It should now look like the following:
    cp /Users/homename/Desktop/_evolute\ tutes  ~/Desktop/foobar
    Hit return.  You should see a file called foobar on your desktop (unless you get an error because the shell didn't like those special characters at the end of the pathname, in which case we have to quote it, but ignore that for now and we can address that in a followup post).  All this did was copy your file to the desktop with a different name, foobar in this case.
    Now I propose that the file foobar is named just that.  If you throw that in the trash, do a get info on it, or drag it back into the terminal window, it should still be just the name foobar.  Nothing else at the end of it.
    If all this goes as I described, then the moral of all this is that however that original problematic file (or files) was created somehow something added those non-printable characters to the end of the name.  In some fonts it shows as best the font being used can show it.  In others they remain invisible because there is no representation in that particular font.
    ...on the other hand, I could just be wrong about all of this!

  • After Effects FFX File Presets and Image thumbnails

    This is a sample piece of code from an effects preset for a text ffx for After effects. The "<xapGImg:image>/" from below is referring to a local url. but it seems to be encrypted or something. Is there a way to make image thumbnails for my ffx files so that the thumbnail can be viewed in bridge. Been looking for the answer but nothing.<br /><br />thanks for helping<br /><br /><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><br /><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1.1-112"><br />   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><br />      <rdf:Description rdf:about=""<br />            xmlns:xap="http://ns.adobe.com/xap/1.0/"<br />            xmlns:xapGImg="http://ns.adobe.com/xap/1.0/g/img/"><br />         <xap:CreatorTool>After Effects 7.0</xap:CreatorTool><br />         <xap:Thumbnails><br />            <rdf:Alt><br />               <rdf:li rdf:parseType="Resource"><br />                  <xapGImg:height>162</xapGImg:height><br />                  <xapGImg:width>216</xapGImg:width><br />                  <xapGImg:format>JPEG</xapGImg:format><br />                  <xapGImg:image>/9j/4AAQSkZJRgABAgEASABIAAD/7gAOQWRvYmUAZMAAAAAB/9sAhAAKBwcHCAcKCAgKDwoICg 8S&#xA;DQoKDRIUEBASEBAUFA8RERERDxQUFxgaGBcUHx8hIR8fLSwsLC0yMjIyMjIyMjIyAQsKCgsMCw4M&#xA;DA 4SDg4OEhQODg4OFBgRERIRERggFxQUFBQXIBweGhoaHhwiIiAgIiIrKykrKzIyMjIyMjIyMjL/&#xA;wAARCACiANg DASIAAhEBAxEB/8QBogAAAAcBAQEBAQAAAAAAAAAABAUDAgYBAAcICQoLAQACAgMB&#xA;AQEBAQAAAAAAAAABAAID BAUGBwgJCgsQAAIBAwMCBAIGBwMEAgYCcwECAxEEAAUhEjFBUQYTYSJx&#xA;gRQykaEHFbFCI8FS0eEzFmLwJHKC8 SVDNFOSorJjc8I1RCeTo7M2F1RkdMPS4ggmgwkKGBmElEVG&#xA;pLRW01UoGvLj88TU5PRldYWVpbXF1eX1ZnaGlq a2xtbm9jdHV2d3h5ent8fX5/c4SFhoeIiYqLjI&#xA;2Oj4KTlJWWl5iZmpucnZ6fkqOkpaanqKmqq6ytrq+hEAAgI BAgMFBQQFBgQIAwNtAQACEQMEIRIx&#xA;QQVRE2EiBnGBkTKhsfAUwdHhI0IVUmJy8TMkNEOCFpJTJaJjssIHc9I1 4kSDF1STCAkKGBkmNkUa&#xA;J2R0VTfyo7PDKCnT4/OElKS0xNTk9GV1hZWltcXV5fVGVmZ2hpamtsbW5vZHV2d3h 5ent8fX5/c4&#xA;SFhoeIiYqLjI2Oj4OUlZaXmJmam5ydnp+So6SlpqeoqaqrrK2ur6/9oADAMBAAIRAxEAPwDjOb Nm&#xA;xV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2b&#xA;Nm xV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV&#xA;2bNmxV2bNmx V2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNm&#xA;xV2bNmxV2bNmxV2bNmxV 2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2bNmxV2b&#xA;NmxV2bNmxV2bNmxV2bNmxV2bNmxV2 bNmxVmX5Z+TbPzZrE9rfPIlrbwmVmhIVq8gqirK3jhr5t8s&#xA;flppelXb6Vq0tzq0JCR2xlRvi5cWqFjHT55JPy IsCmk6zqPIRtI628UrdFKKXav/AAa5FNb/ACyn&#xA;ttf0zTYNTivrjV5ZCxiWnpIhVndvib+bFXn+bPQGjWXk7Sv NUHkvT9GgvZo4Wl1LUblVkdSE5ADm&#xA;rddq0oBXI9a+TNI8yfmTrBa3S30DSConhgURo7gUCDhSgPEs1P44qxT8 rPKlj5m8wS22pIzWMFu0&#xA;rhTxJbkqIK/Scj3mW3sbXX9QttPUrZwTvFCpPI0Q8evzGd98n+YdBu7DXL7SdJg07 T9M5QpcxKqt&#xA;MkaFyzcVG3fqchHkvy7pVn5cu/PWv2R1OeV2axsCvMOzPxHwUIYsx7g0HbFXk2SDyN5eh8x+Zb TS&#xA;rguttLyadoyAwRVJ2JB70ydfmzpGkDy5pGuRaamj6ndECWzRVQ0K8irKoUVXxpXA35D2HreYb2+I&#xA;2t rfip95Gp/DFUtl8i6RJ+Zg8qWkkx0+MqLiRmUyf3YkejBabVA6YRefdD03QPM91pGmvJJb2qxh&#xA;mlIZubosjbq q9OWdB/LD/cz+ZGv64fiRWnaJvaWTig/4DFfINlpnmHzZ5t1vU7eG6s1kYIZ41lVA&#xA;zsVYBwRUJHirxfNnd9Os vJXmTyPrX6O0iO1hsHmiiuGVTMzRosqzeoBy35dK5xXRtKudY1S10y2F&#xA;ZrqRY1PYVO5PyxVBZs75pmneUNA8z ad5Ms9Ih1G/mjMuo39yquUCo0mwdW3anQUHTAGn6Jomo/nD&#xA;fWyafbfo3TrUmS29JPRMtFj3j48a1evTFXiWbP RPly18jarqmv6PZ6HB6Nm3Ge7dEYO78ldYxx/d&#xA;hKbccgn5eeTdDnXVfM2tL6uh6Y0n1eJt1k9Orcm/moKbdzi qG/KzyZo3mC31S+1pHa1slXjwbhQ0&#xA;LsfuGc8l4eq/AcU5HiOtBXYZ6B/xHZXH5YavrdlpkOkxzpLDFDCFHJSf RVzwRN/iOefMVdmzZsVd&#xA;mzZsVdmzZsVdmzZsVdmzZsVez2X+4T8jJJfsS6jzY+NZpfTU/wDAIMjH5KPbr52i9 YgOYJRDX+Yj&#xA;oPorkIk1PUZbVbOW6le0SnCBnYxinSik02xGGaaCVZoHaKVDVJEJVgR3BGKvovyz5Ym0nzr5g1 vU&#xA;Zo2ub0O9jCrcn+rcwzyMP2d+Kj6cJvyykOq6P5thgkUandXUxBJoQsicYifbkDnGDrutG4kujf3H&#xA;1m VeEk3qvzZR+yzVqRiNpqF/ZTGezuZbecggyROyMQeu6kYq9qbSZPJ35Q6vbzSo99NyiufSbkqv&#xA;O6QFOXiqtvh t5ZvtZuvyz08+UXt21S3URSRz7gcS3NfANuCK7ZwB9T1GS2a1e6la2ZubQl2KFieX&#xA;IrWla5djqup6cWawu5rU vsxhkaOo9+JGKsk/MUeck1SBPNlwJrto+cMcZHBFJpQKiqoPyya/kU8E&#xA;llrlkkojv5Qpir1C8WXlT2Y5yG5u7 q7lM11M88x6ySMWY/S2VBcT20olt5GilX7LoSrD6Rir3HRN&#xA;If8ALP

    The XMP packet looks OK--the thumbnail is base64 encoded as it should be.
    You'll have a better chance of a response if you post your question on the After Effects forum--readers there are more likely to be familiar with After Effects and Bridge.
    Don't post the XMP packet text--just that you can't see After Effects thumbnails in Bridge.

  • What adapter must i use to make a projection of an m4v-file (sound and images)

    I have to make a presentation from an m4v-file. What adapters shall i use for sound?

    PrintStream doesn't like the FileWriter, it's all squiggly. Oh, and I found the right event so that it updates every time i type a letter. So, what is this you say about making a FileOutputStream an attribute? I don't know what that means. I'm also not sure what you mean by listener, is that the PrintStream?
    private void jTextPane1KeyTyped(java.awt.event.KeyEvent evt) {
    FileWriter out;
    PrintStream p;
    try
    out = new FileWriter("myfile.txt");
    p = new PrintStream(out);
    p.println (jTextPane1.getText());
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");}
    }

  • Images are not comming out when application is running through jar file.

    I have written an application program using j2sdk1.4.1 that needs your help.
    My application folder's contents.....................................................................................
         C:\Examination\Examination.class <-----This is the main class and application's entry point.
         C:\Examination\ExamBox.class
         C:\Examination\PaperSetterBox.class
         C:\Examination\pspBox.class
         C:\Examination\epBox.class
         C:\Examination\TimerBox.class
         C:\Examination\ReportCardBox.class
         C:\Examination\HelpBox.class
         C:\Examination\AboutBox.class
         C:\Examination\Images\(some jpg & gif files)
         C:\Examination\Sounds\(some au files)
    Compilation Report:     There was no error.
    Execution Report :     Was working properly using the command:- java Examination
    Now, I created a jar file for my application in the following steps.................................
              STEP-1:          Firstly, I created a text file(mainclassInfo.txt) that contains
              the line:--     Main-Class: Examination
              This line would be automatically added to the default manifest file when I would include the                name of that text file with the command to create the jar file.
              Location of the text file I created:     C:\mainClassInfo.txt
              STEP-2:          Then I went to C:\Examination and executed the following command(by using                'Command prompt'):--------------------------------------------------------------------
    jar cmf C:\mainClassInfo.txt Examination.jar Examination.class ExamBox.class PaperSetterBox.class pspBox.class epBox.class TimerBox.class ReportCardBox.class HelpBox.class AboutBox.class Images Sounds
    Finally, I got the jar file:-     Examination.jar
    Double clicking on it application ran as it was expected.
    Then, I thought, that as all the files & folders the application needed to run properly were packaged in the jar file; I should delete all the contents of the folder 'Examination', so that no one could see or use anything of the resources easily. I did that.
    So, then it became only:-- C:\Examination\Examination.jar
    Thereafter, I tried to run the application again and there a problem occurred! The application was running, but the images, those were to be used and shown by the application were missing somehow!!
    Moreover, when I kept a copy of those 2 folders('Images' and 'Sounds') into the C:\Examination and ran the application again all the images came out normally!
    I just can't understand why it's happening so mysterious?
    I don't want to leave anything of the resources in an open place; I mean, outside of the jar file. The images should be used and shown by the application.
    Help me please!

    The Image class itself does not have any methods for loading images from files so you must be using something more. Most methods for loading images from files have an overload that lets you use a URL, so you just need to use that method with a call to getResource like in the other thread. If you can't think of anything else, you can use ImageIcon to load an Image (the Image is returned by a call to ImageIcon.getImage). See also "how to use icons" from the swing tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html

  • Loading images from a jar file

    Hi,
    My application displays images, until it's placed in a JAR file, then it can't display them even though the JAR file contains the images.
    I saw this problem in a previous question which was solved using
    URL url = MyClass.class.getResource("abc.gif");
    Image img=Toolkit.getDefaultToolkit().getImage(url);
    ....which btw didn't work for me either......
    This method should be made obsolete using ImageIcon, which I am using, but the images still won't appear...
    Any suggestions?

    It works fine that way (...getClass().getResource....) until I create the jar file, and then I get a null pointer exception when it tries to load the image.
    When I use
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(("/images/imageName.jpg"));
    the application works but without the images.......

  • Read images from external jar file (Sun's Java L&F Graphics repository)

    Hi!
    I don't know how to read images from an external jar file. Sun has a Java Look and Feel graphics repository that contains a lot of good images that can be used on buttons and so on. This repository is delivered as a jar file, containing only images, and I want to read the image files from that jar file directly without including them inside my application jar file. The application and image jar files will be in the same directory.
    I have absolutely no clue how to solve this. Is it necessary to include the images inside my application jar file or is it possible to have them separate as I want.
    Would really appreciate some help!
    Best regards
    Lars

    Hi,
    There is two ways :
    1) Add your jarfile to the classpath.
    Use the class loader :
    URL url = ClassLoader.getSystemResource("your/package/image.gif");
    Image im = (new ImageIcon(url)).getImage();
    or
    Image im = Toolkit.getDefaultToolkit().getImage(url);2)If you don't want to add the jar to the classpath you can use this (under jdk 1.4):
    import java.util.*;
    import java.util.jar.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class ImageUtilities {
         public static Image getImage(String jarFileName, String fileName) {
              BufferedImage image = null;
              try {
                   JarFile jar = new JarFile(new File(jarFileName), false, JarFile.OPEN_READ);
                   JarEntry entry = jar.getJarEntry(fileName);
                   BufferedInputStream stream = new BufferedInputStream(jar.getInputStream(entry));
                   image = ImageIO.read(stream) ;
              catch (Exception ex) {
                   System.out.println(ex);
              return(image);
    }I hope this helps,
    Denis

  • Images are not coming out when application running through jar file.

    I have written an application program using j2sdk1.4.1 that needs your help.
    My application folder's contents.....................
         C:\Examination\Examination.class <-----This is the main class and application's entry point.
         C:\Examination\ExamBox.class
         C:\Examination\PaperSetterBox.class
         C:\Examination\pspBox.class
         C:\Examination\epBox.class
         C:\Examination\TimerBox.class
         C:\Examination\ReportCardBox.class
         C:\Examination\HelpBox.class
         C:\Examination\AboutBox.class
         C:\Examination\Images\(some jpg & gif files)
         C:\Examination\Sounds\(some au files)
    Compilation Report:     There was no error.
    Execution Report :     Was working properly using the command:- java Examination
    Now, I created a jar file for my application in the following steps.................................
              STEP-1:          Firstly, I created a text file(mainclassInfo.txt) that contains
              the line:--     Main-Class: Examination
              This line would be automatically added to the default manifest file when I would include the                name of that text file with the command to create the jar file.
              Location of the text file I created:     C:\mainClassInfo.txt
              STEP-2:          Then I went to C:\Examination and executed the following command(by using                'Command prompt'):--------------------------------------------------------------------
    jar cmf C:\mainClassInfo.txt Examination.jar Examination.class ExamBox.class PaperSetterBox.class pspBox.class epBox.class TimerBox.class ReportCardBox.class HelpBox.class AboutBox.class Images Sounds
    Finally, I got the jar file:-     Examination.jar
    Double clicking on it application ran as it was expected.
    Then, I thought, that as all the files & folders the application needed to run properly were packaged in the jar file; I should delete all the contents of the folder 'Examination', so that no one could see or use anything of the resources easily. I did that.
    So, then it became only:-- C:\Examination\Examination.jar
    Thereafter, I tried to run the application again and there a problem occurred! The application was running, but the images, those were to be used and shown by the application were missing somehow!!
    Moreover, when I kept a copy of those 2 folders('Images' and 'Sounds') into the C:\Examination and ran the application again all the images came out normally!
    I just can't understand why it's happening so mysterious?
    I don't want to leave anything of the resources in an open place; I mean, outside of the jar file. The images should be used and shown by the application.
    Help me please!

    double post http://forum.java.sun.com/thread.jspa?threadID=582311

Maybe you are looking for

  • Fax and Voice use same DID - SIP/CUBE

    Is there any good way to have inbound Fax and Voice calls use the same DID? I know there used to be a Fax Onramp TCL script, but I thought that was for TDM circuits (T1-PRI). In this scenario, the PSTN comes from a SIP provider to a CUBE router. The

  • HT4865 how to register my ipad mini?

    how to register ipad mini

  • Mavericks and Hitachi GRAID

    Hello. I've a Macbook pro 17-inch, Late 2011. I used to have installed Lion, but since last friday I installed Mavericks. And I been having problems using the Hitachi GRAID external hard drive. I haven't had any problems with others external hard dri

  • Can't install After Effects 6 trial.

    Nothing happens.

  • Regarding OAM-eBusiness suite SSO.

    Hi All, Is it possible to configure SSO between OAM(10.1.4.3.0) -- eBusiness Suite(11i or 12.0 or 12.1) with out installing OSSO in between? Thanks & Regards, Siva Pokuri.