Skip to main content

Why image can not show on my Swing Interface after using Jave web Start

2 replies [Last post]
hchen09
Offline
Joined: 2006-05-05

Hi:
I have a project Interface wrote by Java Swing. I use Java Web Start to launch it. Recently, I added a gif image into my main Interface. It runs normally in local machine (Jar file). But Image can NOT display on Interface using JWS deploy Technology. Can you help to solve this problem?

BTW, I found that using JWS to launch my Java Application very depends on Java Web Server. It will be NOT able to start my java application if web server would be down (Tomcat). Do you have any idea how can we design our Java project with Web server independently? Thanks
Lily

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
evickroy
Offline
Joined: 2004-07-23

> I have a project Interface wrote by Java Swing. I
> . I use Java Web Start to launch it. Recently, I
> added a gif image into my main Interface. It runs
> normally in local machine (Jar file). But Image can
> NOT display on Interface using JWS deploy Technology.
> Can you help to solve this problem?

The image isn't showing because when running from Webstart, you don't have an absolute path to load from. You need to load it relative to the class files in your jar file. Something like this:

// Get current classloader
ClassLoader cl = this.getClass().getClassLoader();

ImageIcon gifImage = new ImageIcon(cl.getResource(gifFileName));

> BTW, I found that using JWS to launch my Java
> Application very depends on Java Web Server. It will
> be NOT able to start my java application if web
> server would be down (Tomcat). Do you have any idea
> how can we design our Java project with Web server
> independently? Thanks
> Lily
Webstart is designed to check the online JNLP file to determine if there is a new version of the application. If there is, then it will download the new version and run it. If not, it just runs the local version. By default, it MUST check with the online version or it won't run. You can tell it to allow offline mode by adding the following element within the "information" element of the JNLP file:

That will make it run even if it can't get the JNLP file from the server.

Here's a link to the Developer's Guide if you are curious what other tags are available in the JNLP file.
http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax....

Hope this helps

aidano
Offline
Joined: 2003-07-08

Does the app need to be run off the web? I have run a Webstart app for our internal network directly from a shared drive on a Windows box on the network.

As for the images, I have seen the same issues. Create a utility class for loading images with a method like:

[code]public static Image createImage(String path) {
return new ImageIcon(SwingUtil.class.getResource(path)).getImage();
}[/code]