This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert an image into Java program

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.........
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out how resources work, then use getClass().getResource(). This returns a URL that you can pass directly to the ImageIcon constructor.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic