users
[Top] [All Lists]

Re: [cinjug-users] Splash Screen from an executable jar

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] Splash Screen from an executable jar
From: Matt Avery <mavery@xxxxxxxxxxxxxxx>
Date: Wed, 12 May 2004 09:26:36 -0400
Delivered-to: mailing list users@cinjug.org
In-reply-to: <20040512111617.73650.qmail@web80606.mail.yahoo.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <20040512111617.73650.qmail@web80606.mail.yahoo.com>
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113
Steve,

On the first line it looks like you are using the String constructor for ImageIcon. I don't think that will work from inside the jar. Try using the URL constructor for ImageIcon and get the URL from the ClassLoader's getResource() method like this.

URL imageUrl = this.getClass().getClassLoader().getResource( filename );
JLabel label = new JLabel(new ImageIcon( imageUrl ) );

If that doesn't work you could try loading a byte array using the ClassLoader's getResourceAsStream() method and use the byte array constructor for ImageIcon.

Steve Metter wrote:
My application displays a splash screen when it starts by putting up a
JLabel containing an ImageIcon containing a PNG file. The entire snippet
of code looks like this:

JLabel label = new JLabel(new ImageIcon(filename));
getContentPane().add(label, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = label.getPreferredSize();
setLocation(MainPanel.HORIZONTAL_SIZE/2 - (labelSize.width/2),
                MainPanel.VERTICAL_SIZE/2 - (labelSize.height/2));
setVisible(true);

It works just fine on my development machine, but the splash screen fails
to display when I run the application as an executable jar.

I've proven that the right code and the image file are all contained in
the jar, and everything else about the application works from the jar
(including other PNG images).

I am not running it as a separate thread, because it doesn't need to be
(although I believe I've eliminated that as the cause of the problem).

Is there something magic about running from an executable jar that would
affect how image files work or how a splash screen works or something?

Thanks for any ideas that anyone can suggest.


--------- You may unsubscribe from this mailing list by sending a blank email addressed to: users-unsubscribe@xxxxxxxxxx

--
Find additional help by sending a blank email
addressed to:
users-help@xxxxxxxxxx




-- Matthew Avery Senior Developer (513) 470-5316 http://www.einnovation.com/

<Prev in Thread] Current Thread [Next in Thread>