dcsimg
add image file to project
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ying_tang
Posted On:   Tuesday, March 30, 2004 12:06 PM

Hi, How can I add image to the project in JBuilder? I've downloaded a demo program which has some code to create image icon as following: ImageIcon icon = createImageIcon("images/middle.gif"); protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = DialogDemo.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } I just don't know how to get the image file to the project I'm working on. many thanks!    More>>

Hi,

How can I add image to the project in JBuilder? I've downloaded a demo program which has some code to create image icon as following:

ImageIcon icon = createImageIcon("images/middle.gif");

protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = DialogDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

I just don't know how to get the image file to the project I'm working on.

many thanks!

   <<Less

Re: add image file to project

Posted By:   zhaohua_meng  
Posted On:   Tuesday, March 30, 2004 12:57 PM

How is the "path" defined? Is it "images/middle.gif"? It seemed the code is using class loader to load the image as a resource. In that case, the parent of "images/middle.gif" has to be in JBuilder's runtime class path. For instance, if "c:JBuilderMyProjectJavaSource" is in your classpath, then your "middle.gif" should have the following hierarchy:


"c:JBuilderMyProjectJavaSourceimagesmiddle.gif"


Hope this helps

About | Sitemap | Contact