3 Replies - 449 Views - Last Post: 21 June 2010 - 08:58 PM Rate Topic: -----

#1 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Images and their paths.

Posted 21 June 2010 - 01:02 AM

Currently in my application, I'm using


tmpButton = new JButton(new ImageIcon("./guiSRC/images/Open24.gif"));


To get an image to a button; however I want to make it so that it'll work in both my IDE, and when its packed into a .jar.


What would be the way to go and get an image file from the project or after its been patched into the jar?
Is This A Good Question/Topic? 0
  • +

Replies To: Images and their paths.

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,993
  • Joined: 20-September 08

Re: Images and their paths.

Posted 21 June 2010 - 02:45 AM

Load it by url. I would recommend an images directory in the root of the application:




tmpButton = new JButton(new ImageIcon(getClass().getResource("/images/guiSRC/images/Open24.gif")));

This post has been edited by g00se: 21 June 2010 - 02:46 AM

Was This Post Helpful? 2
  • +
  • -

#3 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Re: Images and their paths.

Posted 21 June 2010 - 09:53 AM

Thanks; works fine now just have to have an images folder with the jar when I distribute it now.

This post has been edited by Ghlavac: 21 June 2010 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is online

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,910
  • Joined: 06-March 08

Re: Images and their paths.

Posted 21 June 2010 - 08:58 PM

View PostGhlavac, on 21 June 2010 - 10:53 AM, said:

Thanks; works fine now just have to have an images folder with the jar when I distribute it now.

just add the directory to your files to jar

jar -cf my.jar *.class images

Put that link in your Favorites

http://java.sun.com/...asicsindex.html

This post has been edited by pbl: 21 June 2010 - 08:59 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1