This is one of the challenges that most of the beginners using
Eclipse face.There are a number of ways to do so but I will describe one
of the easiest methods to accomplish the task.
The steps are as follows :
Hope this helps…
The steps are as follows :
- In the Package Explorer located on the left, right-click on the src folder of your project.
- Click on the Import option.
- In the Import Dialog Box, choose General -> File System and click Next.
- In the From Directory option click on browse and select the folder in which your image/resource file resides.
- Tick the image/resource files you want to add to your project.
- In the Into Directory option add a folder named "resources" under src so that the into folder now reads <Project-name>/src/resources.
- Click the Finish button.
- Now you will see the desired image/resource file under <Project-name>/src/resources.
- Now wherever in your code you need to provide the name of the image/resource file use the following:
For example if your image file is “picture.jpg”, use
this.getClass().getResource(“/resources/picture.jpg”) - For instance to use the “picture.jpg” as an icon we use:
ImageIcon img = new ImageIcon(this.getClass().getResource(“/resources/picture.jpg”)) ;
Hope this helps…
No comments:
Post a Comment