I am trying to use ImageIcon with Java Swing in order to power a simple Java game. I would like understand how to call a relative filepath from the eclipse workspace inside a project folder? What is the code that can be used to implement the relative filepath in eclipse for an image resource?
Asked
Active
Viewed 2,559 times
1
Andrew Thompson
- 166,747
- 40
- 210
- 420
Luke Greenleaf
- 40
- 2
- 5
-
2I hope this [answer](http://stackoverflow.com/a/9866659/1057230) might be of some help in the given direction. – nIcE cOw Jan 19 '13 at 06:32
1 Answers
5
Use:
getClass().getResource()
Something like this:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images.jpg")));
If images is in your project folder.
joey rohan
- 3,387
- 5
- 29
- 70