1

I finally finished my first real program and have been trying to put some finishing touches on it. One of these finishing touches was packaging it up with icons and everything. The problem is, the icon only shows when I run the jar from the terminal. For example, when I double click the jar to run it I only see the Duke mascot. I am activating the same jar file, but in different ways and getting different results.

Example 1 (Terminal). From Terminal Notice how the icon does show up in my tray.

Example 2 (Double Click). Double click Notice how the icon does not show up in my tray.

Does anyone know how to fix this or what the problem even is?

Thanks so much.

Edit 1: Code

URL iconURL = getClass().getResource("notebook_builder_icon.gif");
ImageIcon icon = new ImageIcon(iconURL);
frame.setIconImage(icon.getImage());
user1472065
  • 115
  • 1
  • 10
  • Sorry it would have just been odd to crop to keep all my tray, title bar, program, terminal, and directory in the same image. – user1472065 Jun 18 '14 at 08:04
  • I'm actually doing it by creating a URL object like "URL iconURL = getClass().getResource("notebook_builder_icon.gif");". I then pass that to the ImageIcon class. Finally, I call frame.setIconImage(icon.getImage). – user1472065 Jun 18 '14 at 08:07
  • Can you show the code you're using. – Paul Samsotha Jun 18 '14 at 08:08
  • Without looking at the code you using for loading images, it's hard to tell. Though please have a look at how to [add images to Java Project](http://stackoverflow.com/a/9866659/1057230), might be this be of some help on the topic :-) – nIcE cOw Jun 18 '14 at 08:09
  • I added the code in an edit, but I'll check out that link! – user1472065 Jun 18 '14 at 08:10
  • but both of your screen shot does not have any image icon. – Arijit Jun 18 '14 at 08:14
  • Arijit, look in the tray going down the left of my screen. Notice one has a hammer and paper while another has the duke mascot. – user1472065 Jun 18 '14 at 08:17

1 Answers1

2

The main difference between the terminal and double clickis the context of the execution location. When running from the terminal, the execution context will be the directory you executed the java command from. When double clicking the Jar the context will be system dependent. You can use System.out.println(new File(".").getCanonicalPath()); to output the path.

And in your terminal, your context was ~/Programming/java, while doublle click makes the context current folder of the .jar file.

ROROROOROROR
  • 959
  • 1
  • 14
  • 31