wood burning stoves 2.0
The moose likes Swing / AWT / SWT and the fly likes Insert an image into Java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Insert an image into Java program" Watch "Insert an image into Java program" New topic

Insert an image into Java program

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I know that when i want to create an image icon i can write this for example

but if i want to run this program in another computer the image will not appear as the path is incorrect
so, I want to save this image in my program so as to run and appear in any computer regardless the path name of the image.
How can i accomplish this?
thanks in advance.........

I Hear I Forget, I See I Remember, I Do I Understand.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20136

Check out how resources work, then use getClass().getResource(). This returns a URL that you can pass directly to the ImageIcon constructor.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: Insert an image into Java program
It's not a secret anymore!