• Post Reply Bookmark Topic Watch Topic
  • New Topic

File path issue in Eclipse  RSS feed

 
james falk
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am wondering how I reference a file that's in my source folder. I have a folder called 'buttons' that my source folder contains, and that folder contains a bunch of images I am trying to use as the ImageIcon for a JButton.

Right now, I am doing this:



and it's not working. I don't know if my syntax for referencing the image location is incorrect or not, so I need an experienced set of eyes to tell me yay or nay.

Thanks for any help you can offer!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usually, if a path starts with a slash, it considers it an absolute path - i.e. c:/buttons/image.png

if your file is actually in a sub directory of your current directory, don't put a slash at the beginning, and it will consider it a relative...

in other words, you can try taking the slash off of your string:

JButton button = new JButton(new ImageIcon("buttons/image.png");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!