Subscribe

RSS Feed (xml)

Powered By

Place Your Ads Here

Adding File in Resource and Retrieving Using Java


I Have Used Netbeans To develop This code so first of all do as shown in picture to add image in your project.
For example your project name is Your Project then expand the Source Package Tree
you will see a pakage named as yourproject.resources expand it too as in image below
 project
now Expand YourProjectApp.properties and right click on YourProjectApp.properties as shown below 
and go to add and click to property as shown in picture
YourProjectApp right click
This dialog will appear
dialog
now fill key as per your choice for ex: hutch
and value is the file name you going to add ex.”hutch.png”
now go to physically your project resources folder for ex.
“F:\Your Project\src\yourproject\resources” and paste the image file you want to add..
now add a jbutton and  jlabel on the jframe or jpanel…on jbutton actionperfomed put this code

org.jdesktop.application.ResourceMap rMap = 
org.jdesktop.application.Application.getInstance(yourproject.YourProjectApp.class).getContext()
getResourceMap(YourProjectAboutBox.class); 
jLabel1.setIcon(rMap.getIcon("hutch"));





Now Your Are all done click the button and see the output





Click below to launch the example





Download Full Source Code

Source Code

0 comments: