The Artima Developer Community
Sponsored Link

Java Answers Forum
Using jar

4 replies on 1 page. Most recent reply: May 10, 2002 4:22 PM by Neel

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Neel

Posts: 4
Nickname: nkd
Registered: Apr, 2002

Using jar Posted: Apr 29, 2002 12:22 AM
Reply to this message Reply
Advertisement
I created a jar file of a program I wrote. In the jar file, I placed some image files (gifs) that my program uses. The jar runs just fine, but the images are not showing up (unless I take the image files and put them in the same directory as the jar file). I know the gifs have been added to the jar because I extracted the jar and I can see all the images. Any ideas?


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Using jar Posted: Apr 29, 2002 1:37 AM
Reply to this message Reply
How do you access the GIF (images) ?
Could you post the code you use to access the file ?
There should basically be no prob accessing the file but you need to give the right directory to access.

Thomas,

Neel

Posts: 4
Nickname: nkd
Registered: Apr, 2002

Re: Using jar Posted: Apr 29, 2002 7:36 AM
Reply to this message Reply
I am working with Swing. I add the gif to an ImageIcon object, add the ImageIcon to a JLabel, and then add the JLabel to a JPanel.

Basically, I am doing something like this (assume the gif image name is QTV.gif)

JPanel myPanel = new JPanel();
ImageIcon image = new ImageIcon("QTV.gif");
JLabel imageLabel = new JLabel(image);
myPanel.add(imageLabel);

john mattucci

Posts: 8
Nickname: mats26
Registered: Apr, 2002

Re: Using jar Posted: Apr 30, 2002 9:50 AM
Reply to this message Reply
JPanel myPanel = new JPanel();
URL url = getClass().getClassLoader().getResource("QTV.gif");
JLabel imageLabel = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(url)));
myPanel.add(imageLabel);

Hope this helps

Neel

Posts: 4
Nickname: nkd
Registered: Apr, 2002

Re: Using jar Posted: May 10, 2002 4:22 PM
Reply to this message Reply
John, I forgot to write and say thanks, that worked perfectly...

Flat View: This topic has 4 replies on 1 page
Topic: how to do configuration to load java standard library? Previous Topic   Next Topic Topic: List of Float numbers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use