3

I made a JavaFX application on Netbeans and I put this code for setting the icon to the window

primaryStage.getIcons().add(new Image("file:sicadcam.png"));

and when I run the project from Netbeans, it works ok: the icon appears on the top left corner of the window and in the taskbar. The image is in the root directory of the project.

When I clean and build the project, it generates two installers: one exe and one msi; and when I install the application and open it, the window doesn't have the icon sicadcam.png, it has the default java logo icon.

How or where can I set the path of the image so that when I install the application the icon appears.

Adrian
  • 769
  • 5
  • 12
  • 18
  • I am facing same problem so please can you just tell me how to set taskbar icon through JavaFX? – vijayk Nov 27 '13 at 06:48

2 Answers2

3

This is only a partial answer to the question as I have been unable to generate a self-contained package which shows the icon for the installed application in the Windows taskbar. I may have missed a step, have an environmental issue or the icon configuration for self-contained applications may be slightly buggy and may be fixed in later releases. Testing was on: jdk7u21, NetBeans 7.3, Win7, InnoSetup.

Get the icon image from a resource rather than a file.

For example, if you place the image in the source directory of your application class:

new Image(MyApplication.class.getResource("sicadcam.png").toExternalForm());

For an installed application, this will only set the icon displayed in the top left corner of the screen. To set the icon for the taskbar, desktop etc, following the instructions in the Self-Contained Packaging section of the JavaFX Deployment Guide is supposed to get you there.

For example to get an icon for the installer on my Windows 7 for my self-contained application, I needed to place the icon in a <netbeansprojectdir>/package/windows/<myappname>.ico (needs to be a .ico for the installer packager to pick it up) file AND ensure my ant path was configured correctly as detailed in How to change JavaFx native Bundle exe icon (hopefully that manual ant configuration won't be required in later NetBeans/JavaFX releases).


Download the Ensemble sample application from Oracle and see how the package directory is laid out there for platform specific icons. Unfortunately when I tried building Ensemble from the command line, I was also unable to get Windows 7 to use the Ensemble icon in the taskbar when Ensemble was installed and executed as a self-contained application.


Ensure your build system copies your icon into the jar file containing your application. To check this, change into the app directory of your installed application and run jar tvf <yourappjar>.jar => it should show the location of the icon resource file in the jar.

Community
  • 1
  • 1
jewelsea
  • 141,332
  • 12
  • 351
  • 391
  • I changed the code to `primaryStage.getIcons().add(new Image(Gansito.class.getResource("sicadcam.png").toExternalForm()));` but I get the message `Exception in Application start method java.lang.reflect.InvocationTargetException` – Adrian May 28 '13 at 05:52
  • @Adrian I tried this out some more and updated my answer with my findings - I don't get an InvocationTargetException so I can't help you with that - but neither did I manage to achieve the result you wanted with the icon in the taskbar :-( – jewelsea May 28 '13 at 07:28
  • 1
    @Jewelsea..I am facing same problem so please can you just tell me how to set taskbar icon through JavaFX? – vijayk Nov 27 '13 at 06:50
0

you can it by using getClass().getResourceAsStream("path.png") the getResourceAsStream("path") is return an input stram for path of any file you are need it for example for icon win.getIcons().add(new Image(getClass().getResourceAsStream("path.png"))); and if you are makking an jar file is run with out Exception