Results 1 to 9 of 9
  1. #1
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Help adding Image to .JAR

    Hey guys im new to java and i have been working on a calculator application for my self in order to help run calculations for work :)
    I wanted to add a image to the .JAR and compile it within the .JAR, thus allowing anyone else running the JAR to view the image when they run the application..
    Does anyone know what i would do? I tried to figure it out my self and ended up messing up the class file, and had to use the clear option in Eclipse in order to restore the application..but now still am stuck against a brick wall trying to figure this out
    So pretty much i just want to include everything in the source folder so all i need to provide is a .JAR thus allowing anyone to see the custom icons and pictures i used :)

    Thank you so much in advance!
    -PsiloCybin

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Help adding Image to .JAR

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Help adding Image to .JAR

    Thank you so much im going to check it out in a few minutes and let you know how it went!!
    Thanks again!

  4. #4
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Help adding Image to .JAR

    Sorry for a double post, I used this method..works perfectly in debug mode.
    //START >> imgj
    imgj = new JLabel();
    imgp.add(imgj);
    getContentPane().add(imgj);
    imgj.setBounds(337, 3, 111, 101);
    imgj.setIcon(new ImageIcon("src\\test.gif"));

    add(imgp);
    imgp.setOpaque(false);

    validate();
    //END << imgj
    Im guessing i took the wrong approach? Or do i just need to add the .GIF to a Class list to get exported along side with the src folder?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Help adding Image to .JAR

    The tutorial I gave you has a section on loading images using getResource. Study it.

    Also, you shouldn't need setBounds. Learn about Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Help adding Image to .JAR

    Thank you so much for your quick reply! Im going to check it out when I get home, and will keep you posted on results.

  7. #7
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Help adding Image to .JAR

    So i was reading the guide and i really cannot grasp the concept its saying, everything i am copying is coming up as errors..
    Maybe is there a video tutorial with a step by step guide? Or maybe you can write me a simple program and comment it so i can visually see what is going on?
    Thanks so much in advance.

  8. #8
    PsiloCybin is offline KushSmoker
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Help adding Image to .JAR

    So after doing research i have found that eclipse has problems compiling images with the .jar file?

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: Help adding Image to .JAR

    No it doesn't.
    I've got several projects that do just that.
    Where is your image located in your project?
    Is it being included in the jar file?
    Where in the jar file is it ending up?
    Finally, what errors are you getting (and how are you running it when you get those errors), and what does the code look like around the point you get those errors?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Adding image in Gui desktop application
    By Mostafa_mech in forum AWT / Swing
    Replies: 5
    Last Post: 01-24-2013, 09:32 AM
  2. Adding a Background image?
    By Mr U in forum Java Applets
    Replies: 3
    Last Post: 10-21-2012, 04:25 PM
  3. Adding image in background
    By nayanjyoti in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 11:47 AM
  4. adding background image to jtabbedpane
    By Gloomy in forum AWT / Swing
    Replies: 1
    Last Post: 08-09-2010, 02:17 PM
  5. adding Image to JButton
    By mayhewj7 in forum New To Java
    Replies: 3
    Last Post: 03-31-2009, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •