How to change default java logo exe icon on the taskbar in javafx?

一笑奈何 提交于 2019-12-11 02:53:30

问题


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 window and in the taskbar. where I have to put the image.

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.


回答1:


You should place the icon in your jar or classpath and then load it through a resource function. E.g. if you place it to your bin folder, into the package where your class is, then the following should work:

primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("sicadcam.png")));



回答2:


I suspect that the image is not handled as a resource and not getting into your Jar file. Can you verify if it is there? (You can do that by Total Commander for example by pressing Ctrl+PgDown to go into the archive).

Another reason might be that NetBeans using a different run configuration and classpath. Where is your image? If it is in the package root (i.e., the folder which contains your top-level package), you can probably access it somehow like: ImageIO.read(getClass().getResourceAsStream("/sicadcam.png")).

Hope that helps something.



来源:https://stackoverflow.com/questions/20237050/how-to-change-default-java-logo-exe-icon-on-the-taskbar-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!