aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Insert an image into Java program" Watch "Insert an image into Java program" New topic
Author

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
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
 
Similar Threads
ImageIcon problem
Refreshing of ImageIcon/JLabel
fit the image to the button size
Adding images to Jar Files (NetBeans)
How do you add image in a JLabel?