Problem with images in swing

I have a game that uses images. Ive created imageIcons and Jlabels, and it all works fine with the full path name of the image file such as
static String fgFile = "C:/Documents and Settings/Gareth/My Documents/My Uni Work/rocket.gif";but when i try to make the program look in another folder (where the image is also stored) images using the folowing code it does not work.
static String fgFile = "/Image/rocket.gif";i have also tried putting ./ and ../ as advised by a friend but nothing works.
The game works fin on my computer but i need to make it work when on a CD
please help

Fixed files like images should always be picked up with getResource() e.g.
ImageIcon rocket = new ImageIcon(getClass().getResource("rocket.gif"));That will look for the rocket.gif file from the classpath, just the way it looked for the .class file of the class in which it occurs. If you put the rocket.gif in the same place as the class file it'll always find it, even if it's in a jar or on-line.
getResource returns a URL but the image loading functions all accept URLs for this very reason.

Similar Messages

  • Problem with Image file

    Hi,
    Iam facing with one problem.I have one swing interface through which I can upload files(back end servlet programme).Now I can upload all types of file but problem with image file it uploading perfectly that means size of the uploaded file is ok but its format damaged.It can not be open.My backend servlet programme is ok coz i tested it with html form it is working perfectly.Problem with swing interface.Plz guide me where I done a mistake.Below r my codes:-
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
         Button=new JButton(Upload);
         Button.setToolTipText("Upload");
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
              int returnVal = fc.showOpenDialog(ActionDemo4.this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fc.getSelectedFile();
    String aa=file.getAbsolutePath();
              textArea3.append(aa);
                   textArea2.append("Local URL:");
    long l=file.length();
              try
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff);
              String str1=textArea10.getText();
    url = new URL ("http://127.0.0.1:7001/servletUpload?x="+str1);
         urlConn = url.openConnection();
         urlConn.setDoInput (true);
         urlConn.setDoOutput (true);
         urlConn.setUseCaches (false);
         urlConn.setRequestProperty("Content-Type","multipart/form-data;boundry=-----------------------------7d11e410e500f2");
         printout = new DataOutputStream (urlConn.getOutputStream ());
    String content ="-----------------------------7d11e410e500f2\r\n"+"Content-Disposition: form-data;"+"name=\"upload\"; filename=\""+aa+"\"\r\n"+"Content-Type: application/octet-strem\r\n\r\n\r\n"+conffile+"-----------------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);
    printout.flush ();
    printout.close ();
    Best Regards
    Bikash

    The errors are here:
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff); (conffile is a String object containing the image)
    and here:
    String content ="-----------------------------7d11e410e500f2\r\n"+"Con
    ent-Disposition: form-data;"+"name=\"upload\";
    filename=\""+aa+"\"\r\n"+"Content-Type:
    application/octet-strem\r\n\r\n\r\n"+conffile+"--------
    --------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);conffie is sent to the server but
    it's non possible to treat binary data as String!
    Image files must be sent as byte[] NOT as String ......

  • Problem with images opened in Photoshop CS 5

    Hi, I have a problem with images that I open in Photoshop CS 5. F. ex. I opened
    the following image:
    The image appears with a purple color in Photoshop. If I hover over the image
    with a tool like lasso, it temporarily regains it´s original color. The image mode is RGB Color, 8 Bits/Channel.
    I resetted the start settings of Photoshop with the CTRL-Shift-Alt-combination, which had no effect.

    The confusion arises from the imprecise error message in the Preferences > Performance dialog box, to wit:
    OK, that seems to be open to misunderstanding indeed.
    The video card: Citrix Systems Inc. Display Driver.
    Could not find a list for CS6 specifically, but the card may fall short.
    http://helpx.adobe.com/photoshop/kb/tested-video-cards-photoshop-cs5.html
    If I invoke View > Proof Colors, the only thing that changes is that the text in the brackets
    Also if you set View > Proof Setup to something different?
    Boilerplate-text:
    Are Photoshop and OS fully updated and have you performed the usual trouble-shooting routines (trashing prefs by keeping command-alt-shift/ctrl-alt-shift pressed while starting Photoshop, 3rd party plug-ins deactivation, system maintenance, cleaning caches, font validation, etc.)?

  • Problem with image url

    Hello,
    today I have a problem with image url. I wanted Image to change when mouse dragged over it. But nothing happened. Any ideas?
    def maxIco: ImageView = ImageView{
    image: Image{
    url: "{__DIR__}ikony/max.png"
    onMouseDragged: function(event: MouseEvent){
    maxIco.image = Image{
    url: "{__DIR__}ikony/max2.png"
    }

    This is working for me:
    src/main/Main.fx
    src/main/icon/image1.bmp
    src/main/icon/image2.bmp
    //Main.fx
    package main;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.input.MouseEvent;
    var changed = false;
    def imgView: ImageView = ImageView {
        image: Image {
            url: "{__DIR__}icon/image1.bmp"
        onMouseDragged: function (e: MouseEvent): Void {
            if (not changed) {
                imgView.image = Image {
                    url: "{__DIR__}icon/image2.bmp"
                changed = true;
                println(imgView.image.url);
        onMouseReleased: function (e: MouseEvent): Void {
            imgView.image = Image {
                url: "{__DIR__}icon/image1.bmp"
            changed = false;
            println(imgView.image.url);
    Stage {
        title: "ImageTest"
        scene: Scene {
            width: 700
            height: 600
            content: [
                imgView
    }I've changed few things to switch image only one time on mouseDragged event.
    It print the image URL.

  • Problem with Image.createImage()

    Hi all!
    I'm writing a simple midlet just to display an image on the screen and I'm having some problems with Image.createImage()
    Here is my code
    Image bg_img;
    ImageItem imageItem1;
    imageItem1 = new ImageItem("", null,ImageItem.LAYOUT_DEFAULT, "");
    try{
    bg_img = Image.createImage("/image.png");
    imageItem1.setImage(bg_img);
    catch(java.io.IOException e){
    e.printStackTrace();
    I'm getting an exception on bg_img = Image.createImage("/image.png");
    I can't understand what is it...:(
    I know for sure that the problem is not "file not found"
    Any one can help me???

    If you are catching IOException, then u may have problem with ur image path. "image not found on the specified path." if ur image is not in the current directiry then put it into current directory. otherwise, If u are using resouce folder and it is already included into the resouce path, then put ur image in that folder..try this..
    Still not get, then please give some detail about ur development toolkit. and ur apllication packaging scheem. are you using ANT?
    Pranav

  • Problem with image gallery

    Hi to all.
    With ios 5.01 I have a little problem with image gallery. As you can see I have only 1 image, but there is always this **** message "download 0 of 46) (sorry, but I'm Italian )
    I've removed my icloud account from settings, but there is nothing to do, this message don't goes away. What I can do? Thanks in advance

    Hello,
    Just adding a gallery I want to do the same slideshow WoodWing's, but in InDesign, if anyone knows of?
    Thank you
    Link video slideshow WoodWing's: http://www.youtube.com/watch?v=Xt6gNaEZ0-M&feature=relmfu
    The first slideshow shown

  • Problems with image scaling

    I'm facing a real problem with image scaling
    I've used several algorithms but it all has defects but the most common thing is the out of memory error after several enlargments...
    does any one know a solution...
    note:
    I've used several packages to do so,but I'm looking for a solution from the jdk itself
    JAlexscorpio

    Did you take into account that the getScaledInstance() -method creates a completly new Image?
    So if you use it like in
    ImageIcon icon1=new ImageIcon("Blah.gif");
    ImageIcon icon2=new ImageIcon(icon1.getImage().getScaledInstance(400,400,SCALE_FAST);
    you will end up with 2 different Images which have their own data and memory requirements.
    even if you use something like
    ImageIcon icon1=new ImageIcon("Blah.gif");
    Image i=icon1.getImage();
    icon1.setImage(i.getScaledInstance(200,200,SCALE_FAST));
    You will need enough memory to store the data for the original image, as well as the data for the scaled
    version of the image, at least for the time that it take the JRE to create the scaled version. You never know when the garbage collector kicks in to delete you old data so it could be that this takes some time and until
    that moment your memory is not available. If your now doing several of the scaling operations, and there is no chance for the garbage collector to do its work, you will run out of memory.
    I hope that might help, if not feel free to post again

  • Problems with Image Variants

    I got two problems with Image Variants:
    1. catalogCache.GetImagePath("Images", id) doesn’t work for some id. The error message is “GetImageVariant error”.
    2. catalogCache.Preload("Images", “Original”)
        catalogCache.Preload("Images", “Thumbnails”)
        catalogCache.Preload("Images", null)
       catalogCache.Preload("Images", "")
    get failed, the status code is -2147483647
    Anyone know how to setup  image variants?
    Thanks.
    Forrest

    status code: -2147483647 is RC_BADPARAM.

  • Copy and Paste Problems with Images

    I'm having the strangest problems with images. I copy an image off of the web for one of my art history classes and I go to paste into another program but, whether it's Keynote, Powerpoint, Photoshop, or Graphic Converter, something always goes wrong: the images definitely lose some of their quality, become brighter in appearance, and get jagged on the edges. This is starting to drive me nuts, especially since it never happened in 10.4 on my iBook G4. Any suggestions?

    Make it an 8-bit file (Image menu > mode).

  • Experiencing problem with image display in LR5

    I have an intermittent problem with images displaying and exporting in LR. It just began a couple of months ago and is totally random - will do it with RAW (CR2) or JPG. It displays this way in all modules - Library, Develop, Slideshow....The image displays fine in a non-Adobe image viewer (Faststone or Windows Viewer). I've reloaded LR5 and PSCC and is still persists. I know the image file is fine. It also has begun effecting older images that were showing up just fine a while ago. I just loaded about 200 images and maybe 3 or so have this viewing problem in LR & PS. Has anyone else experienced it and have a suggested fix? My graphics card has the latest drivers and shows no problems with other applications. Here is the same image - one a jpg export from Lighroom, the other a save as jpg from Faststone. HELP!

    This is almost always a hardware problem, causing corruption of the file. The difference you see between Lightroom and other software is that Lightroom is accessing the full RAW image, while the other software is trying to read the embedded JPG preview.
    To figure out exactly what hardware is the problem, you need to try different transmission paths and hardware ... different camera cards, different card readers or USB cables/USB ports, different hard disks, etc. Eventually you should be able to isolate the problem.

  • My daughter's older Ipod Touch is having a problem with images becoming pixilated when taken from an e-mail and placed into her camera roll. ( She wants to put on Instagram ) Any help?

    My daughter's older Ipod Touch is having a problem with images becoming pixilated when taken from an e-mail and placed into her camera roll. ( She wants to put on Instagram ) Any help?

    I think that may be a consequence of the email provider she is using. Some services (AOL is one example) inspect and modify email attachments, particularly photos, resulting in reduced resolution compared to the email that was sent.
    The iPod does not do this. The resolution of the picture in the email she receives will be identical to what is imported.

  • URGENT: Heap space problems with image resizing

    I'm creating a Swing program, with an InternalFrame-type interface. One of the frames contains a .gif file background and then primitive G2D objects are drawn on top of it.
    The background image loads and displays fine at its original size, but I've added code for when the window resizes, and resizing the image causes the VM to give me an OutOfMemory exception.

    I tried this without any problem (with a gif of 137 kb):
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ImageFrame extends JFrame {
        public ImageFrame() {
            initComponents();
            Toolkit T=this.getToolkit();
            im0=T.getImage("C:\\sophie.gif");
            MediaTracker mediaTracker = new MediaTracker(this);
            mediaTracker.addImage(im0, 1);
            try {
                mediaTracker.waitForID(1);
            } catch (InterruptedException ie) {
                System.err.println(ie);
            jInternalFrame1.add(new MyPanel());
        private void initComponents() {
            jDesktopPane1 = new JDesktopPane();
            jInternalFrame1 = new JInternalFrame();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            jInternalFrame1.setResizable(true);
            jInternalFrame1.setVisible(true);
            jInternalFrame1.addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent evt) {
                    jInternalFrame1ComponentResized(evt);
            jInternalFrame1.setBounds(0, 0, width, height);
            jDesktopPane1.add(jInternalFrame1, JLayeredPane.DEFAULT_LAYER);
            getContentPane().add(jDesktopPane1, BorderLayout.CENTER);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-800)/2, (screenSize.height-500)/2, 800, 500);
        private void jInternalFrame1ComponentResized(ComponentEvent evt) {
            width=jInternalFrame1.getWidth();
            height=jInternalFrame1.getHeight();
        public static void main(String args[]) {
            new ImageFrame().setVisible(true);
        private int width=500,height=300;
        private Image im0;
        private JDesktopPane jDesktopPane1;
        private JInternalFrame jInternalFrame1;
        class MyPanel extends JPanel {
            public void paint(Graphics g1) {
                g1.drawImage(im0,0,0,width,height,this);
                g1.dispose();
    }

  • Email attachment in PDF problem with Images

    Hi All,
    Can any one tell me how to solve the problem with Email attachment in PDF. If i remove the logo of the client in the Smartform i am getting the Email attachment fine but when i put back the image in the smartform the PDF is giving error and not opening the attachment.
    Regards,
    Lakshmikanth.

    Hi All,
    Can any one tell me how to solve the problem with Email attachment in PDF. If i remove the logo of the client in the Smartform i am getting the Email attachment fine but when i put back the image in the smartform the PDF is giving error and not opening the attachment.
    Regards,
    Lakshmikanth.

  • Lightroom 4.2 - Experiencing problems with images viewed on 2nd monitor

    Hi All,
    This problem seems to have started with my updating from 4.1 to 4.2.  I have my second monitor set as Loupe - Normal and Fit.  As I crop an image on my main monitor, the 2nd monitor view does not always change to the cropped view.  If I switch to a different photo and then back to the one I just cropped, the 2nd monitor view will then show the cropped image, but it is almost always blurry.  Sometimes I can click the image in the 2nd monitor view to change to a 1:1 view and it will look sharp, and then click again back to Fit and then it too will be sharp.  Other times I get a message in the 2nd monitor view that says "no image selected" and bouncing back and forth between a different image will correct this.
    This all started off with the majority, but not all cropped images showing as blurred and progressed to what I have described above.  I seriously though I had a focus problem with my camera!
    Is anyone else experinecing this since updating?  Suggestions?
    Below is the suggested information to provide...
    What version of Lightroom? 4.2
    Have you installed the recent updates? Yes, 4.2
    What operating system? Windows 7 Ultimate 64 bit
    What kind(s) of image file(s)? All images are converted to .dng upon import
    If you are getting error message(s), what is the full text of the error message(s)? No error messages.
    What were you doing when the problem occurred? I am in the develop module cropping images etc.
    What other software are you running? Silver Efex Pro 2, but I have had that installed in many prior versions of Lightroom
    Tell us about your computer hardware. How much RAM is installed? 32 GB - Yes, I know - overkill... 
    How much free space is on your system (C:) drive? 119 GB of 223 GB of my solid state drive c:\
    Has this ever worked before? Yes
    If so, do you recall any changes you made to Lightroom, such as adding Plug-ins, presets, etc.? No other changes other than updating to 4.2
    Did you make any changes to your system, such as updating hardware, printers or drivers, or installing/uninstalling any programs?  No, no other changes.
    Thanks!

    Same problem.   Not a soloution, but this may be relevant.
    http://forums.adobe.com/message/4782916#4782916
    Alan

  • Problem with image opened in Photoshop

    Hi all,
    I am having a strange problem with an image opened from Aperture in Photoshop. Though the image looks fine, something is amiss. Most notably when I try to use the shadow/highlight command in Photoshop, the image actually darkens (highlights are set to zero amount). If I export the image as a jpeg and open it in Photoshop, the s/h command works as expected. If I export as a .psd file and open it, the s/h command again darkens the image. Interestingly, the .psd file thumbnail shows orange with read streaks through it, but opens as it should. Corrupted .psd conversion maybe?
    Any thoughts or suggestions would be appreciated.
    Thanks,
    Steve

    Additional info:
    Same problem with a series of photos taken about the same time.
    Other photos work fine.
    I exported the original .nef file, opened it in camera raw/photoshop. Works fine.
    Corruption/bug in the .psd conversion looks more likely unless I'm missing something. . . .
    Help!!!

Maybe you are looking for

  • Code works on new form not on older form

    Hi I am trying to change an existing form (add some code). I tested the code in a new form I create on my computer but when I do the same on a form supplied and created on a different computer the code won't work What I see is that the form propertie

  • Server0 not starting

    Hi, I my solman system, server0 is not starting. could anyone please help me. I am attaching the trace file of server0. trc file: "D:\usr\sap\ISM\DVEBMGS00\work\dev_server0", trc level: 1, release: "700" node name   : ID4047650 pid         : 3496 sys

  • Outlook Integration Error

    Hi experts, The Outlook Integration addon sometimes gives me the following errors when SAP starts: Failed to connect to SBO-COMMON or Failed to Connect to Company or Failed to Connect to Licence Server Only a few times start in the right way. I found

  • Issue with PCL1 cluster table

    Hi Guies We have  a custom infotype 9003 which has a comment box where the user can enter long texts. that text goes to PCL1 TX cluster table. The client wants to have a custom utility which will upload the texts from flat file to PCL1 cluster table.

  • Iphoto can't read scanned photos

    New mac user. trying to create a slideshow and add a few songs. first I can't seem to see scanned images in iphoto. I copied the scanned images to the library but the photos do not show up. When I try to copy them I get an error message that the file