Problem with ImageIcon in Eclipse driving me mad...

Hi Guys,
I'm back to Java programming after taking a break of a year or two and have encountered a problem that I'm left scratching my head with.
I have an ImageIcon which does not display its background image if I run the app in Eclipse, but does display if I run in a free app called RealJ or run from the console. Here is my code:
import java.awt.*;
public class MyPet extends Frame
     private JPanel j1, j2, j3, j4;
     private ImageIcon bg;
     private JLabel bgLabel;
     private statusPanel sPanel;
     public MyPet()
          this.addWindowListener     (new WindowAdapter(){
               public void windowClosing(WindowEvent e){
                    dispose();
                    System.exit(0);
          bg = new ImageIcon("misc/bg.jpg");
          bgLabel = new JLabel(bg);
          sPanel = new statusPanel();
          setLayout(new GridLayout(2,2));
          j1 = new JPanel();
          j1.add(sPanel);
          j2 = new JPanel();
          j2.add(bgLabel);
          j3 = new JPanel();
          j4 = new JPanel();
        j2.setBorder(BorderFactory.createLineBorder(Color.black));
        add(j1);
        add(j2);
        add(j3);
        add(j4);
     public static void main(String args[])
          MyPet f = new MyPet();
          f.setSize(600,500);
          f.setVisible(true);
          f.setTitle("My Pet Application - Virtual Pet Simulator");
}Can anyone help?? The image is definitely named bg.jpg and is definitely in the misc directory located in the bin directory along with the Class files. As I say, running the app from the console works fine.

Why is this a problem?
if it works outside of Eclipse then take it up with Eclipse.

Similar Messages

  • Problem with package in Eclipse

    I am doing in Java codes. There is big problem with those error:
    package org.eclipse.emf.ecore.xml.type.internal;What I should to do that? Do you think I need to download some package from somewhere for Eclipse?
    I have already Eclipse. Please help me how to do that. Thanks.

    I wrote codes in there. But there is some errors in there because they said that I don't have package exist in Eclipse. I have no idea why.
    Those lists below got red line:
    package org.eclipse.emf.ecore.xml.type.internal;
    import org.eclipse.emf.common.util.WrappedException;
    import org.eclipse.emf.ecore.xml.type.InvalidDatatypeValueException;
    import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;I tried to run it and the errors said:
    InvalidDatatypeValueException cannot be resolved to a type.
    The declared package "org.eclipse.emf.ecore.xml.type.internal" does not match excpected package"
    The import org.eclipse cannot be resolved
    WrappedException cannot be resolved to a type
    XMLTypeUtil cannot be resolved{code}
    What is wrong with it? Do you think there is missing plugin package or what? Where can I find a package for that?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problems with syncing appointments from icloud i made with my earlyer iphone

    Im having problems with my calendar after switching from iphone 4 to 4s. All the appointments in my calendar i made with the old iphone 4 will not sync to my new 4s. I can see them i icloud on my win pc but not on my 4s..
    Theres no problem with syncing new appointments from icloud to iphone 4s. Only the old ones i made in icould my the old iphone 4.
    I would like to have all the old ones on my iphone too.. Anybody got a suggestion to a solution???

    It seems that the calendar wont let me make new appointments in the time before i activatet my present iphone. But all the subscriptions and birtsdays is there long before.. So why cant icloud do the same??

  • Problems with installation of eclipse

    When I try to install eclipse on my machine, It says some error and I get the following error message in the log file.
    SESSION ----------------------------------------------------------------------
    !ENTRY org.eclipse.core.launcher 4 0 Nov 18, 2005 15:49:13.621
    !MESSAGE Exception launching the Eclipse Platform:
    !STACK
    java.lang.RuntimeException: Could not find bootstrap code. Check location of boot plug-in or specify -boot.
         at org.eclipse.core.launcher.Main.searchForBoot(Main.java:468)
         at org.eclipse.core.launcher.Main.getBootPath(Main.java:438)
         at org.eclipse.core.launcher.Main.basicRun(Main.java:281)
         at org.eclipse.core.launcher.Main.run(Main.java:747)
         at org.eclipse.core.launcher.Main.main(Main.java:583)
    Could anyone please help me in solving this problem.

    Which version of eclipse are you trying?
    Have you tried the eclipse web site?
    Eclipse does not require a special install. All you should need to do is unpack the zip archive. You have to unpack all of it.

  • Strange problem with zen micro (I'm going mad!!

    merry xmas!! I've bought a zen micro in seprember, flashed with .xx firmware; I always used it with windows 2000 with no problem, but... problems began when I've installed a pci card usb 2.0 on my pc; the card worked finely with everything but not with zen micro, that's to say that everytime I tried to import songs by media explorer, the program often wasn't able to import songs; so I've installed windows xp and flashed zen micro with 2.xx firmware (I've installed also service pack 2 and wmp0), but things have gone wrong!!! now everytime I connect zen micro to pc, xp asks the drivers, and it doesn't want neither the driver I've found on creative's cd, nor drivers downloaded from creative's site!! And it's not finished: now zen micro is without firmware and everytime I'm trying to flsh it, a dialogue box says that the player is not connect!!!
    can anybody help me? otherwise I'll have to write to creative support for a substitution...
    please help me!!!!!

    Strange. Unfortunately MTP connection problems are very tricky to solve. It's hard to know whether the firmware upgrade was partially successful, and whether you are on v or v2 firmware. It sounds like v2 firmware, due to the connection problems with MTP.
    The drivers for the v2 firmware are provided by Windows Media Player 0, and are located in the C:\WINDOWS\INF directory. You could try pointing there.
    As the player has no firmware though you have to go into recovery mode, choose "reload firmware", then connect to the PC (see if it's detected) and run the firmware update again.
    If this doesn't work try and find another PC, say a friend's, that meets the requirements of Win XP + SP/2 + WMP0, and see if you can update.
    In terms of resolving the connection problem if it continues, have a look at this thread, particularly the reply by DM, which goes through some of the troubleshooting to solve MTP connection problems. Also look for the link "problems with connecting using MTP firmware" in the FAQ post.

  • Problem with debug servlet Eclipse 3 tomcat 5

    I have configured Eclipse 3 with Tomcat 5.0.28 and tomcatPulginV3
    but, I have problem to debug my servlet
    I have error message
    help me it is urgent
    Failed to connect to remote VM. Connection refused.
    java.net.ConnectException: Connection refused: connect
    java.net.PlainSocketImpl.socketConnect(Native Method)
    java.net.PlainSocketImpl.doConnect(Unknown Source)
    java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    java.net.PlainSocketImpl.connect(Unknown Source)
    java.net.Socket.connect(Unknown Source)
    java.net.Socket.connect(Unknown Source)
    java.net.Socket.<init>(Unknown Source)
    java.net.Socket.<init>(Unknown Source)
    org.eclipse.jdi.internal.connect.SocketTransportImpl.attach(SocketTransportImpl.java:47)
    org.eclipse.jdi.internal.connect.SocketAttachingConnectorImpl.attach(SocketAttachingConnectorImpl.java:103)
    org.eclipse.jdt.internal.launching.SocketAttachConnector.connect(SocketAttachConnector.java:131)
    org.eclipse.jdt.internal.launching.JavaRemoteApplicationLaunchConfigurationDelegate.launch(JavaRemoteApplicationLaunchConfigurationDelegate.java:75)
    org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:569)
    org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:788)
    org.eclipse.debug.internal.ui.DebugUIPlugin$6.run(DebugUIPlugin.java:955)
    org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)Thanks

    Check your packages which you are importing....

  • Putting an image into a jtextpane / problems with ImageIcon and path

    So here is what I am trying to do. I would like to be able to allow the user to add images to a jtextpane which will also contain rtf text.
    My current plan is to have a drag event or some other event run the actual code to place the image in the jtextpane. So my first attempt was just to first write a test program to add an image to a textpane using a hard coded path. The problem is i cant seem to create an imageicon using a canonical path because the image icon constructor wants a relative path(from the docs).
    So i guess the best solution would be to convert the canonical path to a relative path. I have this forum and google many times and found many similar posts but none with a real solution (people just reply, why would you want to do that etc.).
    So i either need to convert the path or if any one has a better suggestion to allow users to add images to the jtextpane. Any suggestions?

    show the path you are trying to use.
    Edited by: JacobsB on Mar 13, 2008 1:11 PM
    and try this
    URL url = getClass().getResource(pathName);
    ImageIcon(url);

  • Having some problems with ImageIcons and JLabels

    I'm making a checkers game, and so far it's going pretty well.
    I've got the basic game down, and you can move pieces, jump, your turn ends when you can't jump anymore, etc...
    However, I've had three problems:
    1.) I'm using JLabels to display my board (8 x 8.. well actually 9 x 9 for an outer row labelled A,B,C,D.. 1,2,3,4...) Anyway, I create the JLabels using something that looks like \:
    JLabel square = new JLabel(new ImageIcon("pic.png"));
    Now, the picture loads properly, but it seems like the picture is being cropped, and the top and bottom are getting chopped off, so my 36 x 36 pixel *.gif appears to be 36 x 30.
    You can see how there is a gap created in:
    http://img235.imageshack.us/img235/7765/prob13ky.jpg
    Now the problem may be with the GridLayout I am using, but I set the distance between the components in the container to be 0, 0 so I don't think that GridLayout is chopping my icons. I've also tried setPreferredSize(new Dimension(36,36))
    for both my ImageIcons and JLabels and for my container (which I set to size 2000,2000, just to make sure there was room). If anyone can help me, it's be appreciated.
    2.) I used to be able to view my outside row/column of squares that said A,B,C,D.... and 1,2,3,4... with the square in the corner having a random pic. For some reason now (have no clue why) I now see only the pic in the corner, and then a little gray smudge diagonally under it.
    Pic:
    http://img347.imageshack.us/img347/8308/prob24im.jpg
    I don't know what's wrong. I'm pretty sure it's none of the new methods I've written, as those are all in my static void main (String[] ar) ...... and if I comment all the methods in my main except where I first make the JFrame and set it visible, it still turns out like that. repaint() doesn't help.
    3.) For some reason, when I move another window (AIM, the console window, etc...) over my Swing window, it "erases" (turns gray, just wipes clean) the part where I have my squares that have pieces.
    What's weird is that:
    The border pieces (err.. my one visible corner piece from my second problem) don't get wiped, and some debugging text and JLabels (in a different JPanel) are fine. I don't think the JPanel matters though; the border pieces and the playing squares (which get wiped) are in the same JPanel and same array of squares.
    repaint(); also erases ALL of my playing squares, whereas moving a window over them would only erase the part that the window covered.
    Also, I added a mouseListener so that whenever I move the mouse over a square, it changes the image (to a tinted version, so you know the mouse is over it) and when you move the mouse away, it returns to normal. However, if I wildly swing the mouse around the area, it seems to lock up and freeze for a few seconds. Is there anything I can do to prevent this??
    Thanks in advance.

    It is hard to tell what your problems are without any code at all (I saw your images, but that doesn't make it easy to see what is wrong in your code). If you do post code, please use code tags (see button above posting box).
    I've seen your MouseListener problem before--we had the exact same issue in our code at work. It would freeze up while it processed all of the mouse events (unbearably slow). I'm not at work right now, so I don't recall how it was fixed. Essentially, you need to only process the event periodically. You need to only update the image if the mouse switches squares. Or, only update the image if the distance from the last mouse event is more than some specified amount. We might also have checked the time difference between mouse events before processing a new one. I could look at the code at work tomorrow, if you are still having trouble.

  • Problem with ImageIcon

    Hi,
    This is my code
    public class IconTest extends JFrame {
        /** Creates a new instance of IconTest */
        public IconTest() {
            setSize(300,300);
            JPanel pane = new JPanel();
            ImageIcon logo = new ImageIcon("image.gif");
            JLabel image = new JLabel(logo);
            pane.add(image);
            setContentPane(pane);
            setVisible(true);
        public static void main(String[] args) {
            new IconTest();
    }this code doesn't work : I have to put the entire path for the image file...
    something like this :
    ImageIcon logo = new ImageIcon("H:/Data/Project/.../image.gif");  how can I resolve this problem ? Thanx

    You can load an image in two ways:
    If the image is inside a jar you need to refer to it using the full package name like
    com.brench.mli.mlidatabase.graphics.<image>
    and you have to load it using the ResourceBundle class.
    If the image is on the file system (and this seems the case) you can use the ImageIcon
    class but you have to supply the full image path. This is the reason why the line
    new ImageIcon("H:/Data/...");
    works. Java tries to load the "image.gif" image from the current directory where you
    launched your application. If you do a cd H:/Data/... and run your application you should
    be able to load it properly.
    A tip I use to discover the directory of my application is this:
    String dir = ClassLoader.getSystemResource("<package/myclass>.class").toString();
    Then, inspecting the dir variable I'm able to discover where I am.

  • Problem with JVN running Eclipse

    Hi guys!
    Recently I have downloaded Eclipse IDE and when I execute IDE it appears me a window error that says:
    A Java Runtime (JRE) or JAVA Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locations:
    D:\eclipse\jre\bin\javaw.exe
    javaw.exe in your current Path
    I have been seeing on the environment variables and I have on the PATH variable the jdk (=%PATH%;%JAVA_HOME%\jdk\bin,), so I don�t know where is the problem. Also I have put javaw in an MSDOS windows, but again, I cant run Eclipse.
    Anybody knows how I can solve it?
    Thanks

    if using Windows, add your JAVA install loaction like C:\Sun\SDK\jdk\jre\bin to system variables>path before run eclipse.exe.

  • Printing Problem with Google and Yahoo Driving Directions using Safari

    I am running Safari 4.0.2 on an iMac running Mac OS X 10.5.8. When I try to print Driving Directions from Google or Yahoo Maps, I see the text (and map) completely rendered in the print preview, but the print out does not include the text content for the Directions. The map is OK. Print out includes the lines and graphics from the Directions page but the text areas are blank. I am printing on an HP DJ 5500. MapQuest Driving Directions print out completely. But I can't get the text in the Directions section to print for Google or Yahoo even though it looks fine in the print preview. Has anyone had this issue? What can be done to resolve it?
    Message was edited by: Carol Foote

    Hi,
    running Safari 4.0.2 on an iMac running Mac OS X 10.5.8.
    You need to update Safari. You should be running Safari 5.0.3
    Click the Apple () menu (top left in your screen) then click: Software Update ...
    And go to ~/Library/Preferences. Move the com.apple.print.PrintingPrefs.plist file to the Trash.
    Restart your Mac after the update is installed.
    Carolyn
    Message was edited by: Carolyn

  • Problem with downloading "Stanford Eclipse for Macintosh Users"

    Hi, recently I tried to download Stanford Eclipse for Macintosh Users . The program downloaded but did not open. If you need any additional details, I would be happy to provide them. Thank you for the help!
    Computer: Mac OS X 10.9.5
    Stanford Eclipse Download: http://see.stanford.edu/see/materials/icspmcs106a/software.aspx

    The link your professor provided only downloads, and does not install anything. Look for it in the Downloads folder. The folder they download is zipped, and it may un-zip automatically. They expect you to drag the unzipped 'Eclipse' folder to a location you find convenient.
    The package it downloads is a fairly old 32-bit version for Mac OS X 10.5 or later. The link to the Eclipse developer site has newer versions including a 64-bit version if you have a Mac running 64-bit kernel or 10.8 or later.
    AS Kappy suggests, executing eclipse.app should give you error messages that point out any deficiencies.
    If you need java and are running 10.7.3 or later, oracle java is provided ONLY at this site:
    http://java.com

  • Problems with Lomboz and eclipse

    I have Eclipse 3.1 installed, latest version of Lomboze and Tomcat 5.0.30.
    I created a new j2ee project, it has indx.jsp in it by default, so i tried to run it, but when ever i try to load tomcat through eclipse I get thrown to debug perspective and
    get LogFactoryIpl.getLogConstructor() line 374
    SOURCE NOT FOUND
    <button for editing source lookup paths>
    error
    I have followed the install guied on lomboz web page
    http://www.objectlearn.com/support/docs/installation/install.jsp
    to the letter except when they where asking to separate binray and source files i didn't have have New Project in options->Java

    it is sipposed to be
    get LogFactoryImpl.getLogConstructor() line 374

  • Problems with Tomcat & Eclipse on MacOSX

    Hi everybody. I have a problem with Tomcat and Eclipse. I must make an application with JSF for my dissertation and i even become a new Mac user so i have some problems. I have installed Eclipse 3,3 Europe on Mac OSX 10,4, also I have installed Tomcat 5,5 setting up environment variable and users of Tomcat. Well, when I try to connect them creating a new server in Eclipse and select Tomcat as server and relative folder of origin, the problems begin. When I try to run on server a JSF project(naturally I have imported all the necessary libraries) it give this error to me: Could not load the Tomcat incomplete serveur configuration at /Servers/Tomcat v5.5 serveur at localhost-config.The configurator mau be corrupt or. Reason: Could not load the Tomcat incomplete serveur configuration at /Servers/Tomcat v5.5 serveur at localhost-config.The configurator mau be corrupt or incomplete. On what it can depend? It is possible that is a JRE problem? I do not find the folder jre on my file system(are novice with the mac). Thanks to all.

    This seems like a question that would be better put to an Eclipse forum.

  • Having a problem with app files and fonts between OS

    I work in a prepress department, and we are have issues with files that are coming from 10.4.11 to 10.5.8. The 10.4.11 is a power PC and the 10.5.8 is Intel. Fonts get corrupt and display as a unix file with 0 file size and application files like Quark loose there ID and come up as a document file. I think this has to do with the OS difference. Is there any way that this can be fixed???

    Well we are having the the same problem with folders. Jobs that are made on a 10.4 Mac, sometimes you can't see the contents of the folder on a 10.5 Mac. And there is no pattern.
    And if you take the contents out of the folder and put it loose using a 10.4 Mac, you can see it on a 10.5 Mac
    Also if we put a .dfont on the end to the font using a 10.4 Mac, you can see the font on a 10.5 Mac.
    This is all very strange. There are no patterns and no reason why one folder would work and the other does not. Just checking if there is something that could be causing a problem between the OS's.

Maybe you are looking for

  • How can I create a new folder in the photo album?

    I have photos in "camera roll" on my iPhone4 that were taken on my iPhone3 and I would like to start a new album so I can separate photos taken with my iPhone4.

  • Time Machine, Disk Utility, and clearing out corrupted snapshots

    Hi, all. I've been having some troubling issues with Time Machine and could use your collective insight. I have a 500GiB external USB2 disk that I've been using for Time Machine since December (the oldest snapshot in Backups.backupdb is named 2007-12

  • Open multiple forms, few in Enter-Query mode

    Hi All, I want to open multiple forms from a form using open_form built-in. If user clicks on different items of the parent form different child forms are invoked. But if one child form is opened in Enter-Query mode (I have 'enter_query;' in its when

  • Cant connect to safari-used to work fine!!

    i just returned from out of the country...my wireless worked fine before i left, while i was away and i get home and cant connect!  My boyfriends computer is fine, i am using it now.  I have spoken with my provider and they couldn't help me-after tak

  • Is there a firewall in iOS8 when using public WiFi?

    If I am not able to use cell connections because I am out of range, but there is a public WiFi, I want to know my phone can't be seen by anyone I don't want to see it. Is there a firewall or something similar in iOS8 to cloak the phone as there is in