This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes a icon path in a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "a icon path in a java program" Watch "a icon path in a java program" New topic
Author

a icon path in a java program

Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147

Hi,

I have an icon is in other project folder named icons.
How do I set the path as below:

private String ICON_PATH = "....../icons/icon_name.png";

Thanks for your help.
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Greetings ,

Personally I dont like the fact of putting hard coded paths inside my java classes. I put all such paths in a properties file and read them from the properties file. Secondly what problem are you facing ? I mean you specified the path as "/path/to/icons/icon_name.png" and java couldnt find the file ( threw a FileNotFoundException) or there is some other issue ?


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

The tutorial section on Loading Images Using getResource says it better than I ever could, along with illustrations.

If by 'other project folder' you mean that the image file resides in another project of your IDE, you need to add that project or its .jar as a library. Note that projects are a feature of certain IDEs and are not a part of the Java programming language.


luck, db
There are no new questions, but there may be new answers.
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
Saif Asif wrote:Greetings ,

Personally I dont like the fact of putting hard coded paths inside my java classes. I put all such paths in a properties file and read them from the properties file. Secondly what problem are you facing ? I mean you specified the path as "/path/to/icons/icon_name.png" and java couldnt find the file ( threw a FileNotFoundException) or there is some other issue ?


I have to get the icon that is under another project folder named icons folder.
If you know how to get it, please let me know.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Please re-read Darryl's post.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: a icon path in a java program