Using absolute paths with a URL in SerializableImage

Article ID: 941
Last updated: 05 Feb, 2008
Article ID: 941
Last updated: 05 Feb, 2008
Revision: 1
Views: 2482
Posted: 22 Sep, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


How do you get absolute pathnames using a URL to work in SerializableImage instead of relative pathnames?


Cause


The standard way to specify images in SerializableImage is relative pathnames. Some programmers might want to specify an absolute pathname to a particular file in the local machine (which does limit portability). The JWidgets example code for the ImageButtonDemo contains the line:

new SerializableImage(getClass().getResource(../../images/sixstates.gif);

The image in question is on /home2/users/nice/sixstatessmall.gif. The localhost refers to the local machine, instead of an external machine such as www.roguewave.com.


Action


Substitute the following:

URL url=null;
try {
url = new URL(file://localhost/home2/users/nice/sixstatessmall.gif);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
SerializableImage image = new SerializableImage(url);
This article was:   Helpful | Not helpful
Report an issue
Article ID: 941
Last updated: 05 Feb, 2008
Revision: 1
Views: 2482
Posted: 22 Sep, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category