简体   繁体   English

如何更改我的 java 应用程序图标的图像

[英]How to change the image of my java app icon

I have searched for an answer to this question in many places, but none of the answers satisfies what I really want.我在很多地方都在寻找这个问题的答案,但没有一个答案能满足我真正想要的。 There are variations of the solution, but they all go along the lines of the code I have below:解决方案有多种变体,但它们都是 go 沿着我下面的代码行:

MainFrame() {
   ImageIcon logo = new ImageIcon(getClass().getResource("file_path"));
   setIconImage(logo.getImage);
   //the rest of my code
}

public static void main(String[] args){
   MainFrame mf = new MainFrame();
   mf.pack();
   mf.setVisible(true);
}

Basically, load an image or an image icon from a file, and then call the setIconImage() method from the JFrame. This sets the icon image in the title bar of the window, and also the icon image in the task bar when the app is active.基本上,从文件加载图像或图像图标,然后从 JFrame 调用 setIconImage() 方法。这会设置 window 标题栏中的图标图像,以及应用程序运行时任务栏中的图标图像活跃。 But it does not set the icon image of the app icon.但它没有设置应用程序图标的图标图像。 In order to show you more clearly what I mean, please see the image I attached, where I circled the three icons.为了更清楚地向您展示我的意思,请看我附上的图片,我在其中圈出了三个图标。 The one with the Java coffee cup is the one I haven't been able to change.带有 Java 咖啡杯的那个是我一直无法更换的那个。

the taskbar, my app, and the window of my app任务栏、我的应用程序和我的应用程序的 window

Can somebody help me set the image of the app icon itself (not just the task bar and title bar icons)?有人可以帮我设置应用程序图标本身的图像(不仅仅是任务栏和标题栏图标)吗?

I was not able change the image of the jar file itself as it sits inside a directory, as shown in the image attached to my question.我无法更改 jar 文件本身的图像,因为它位于一个目录中,如我的问题所附图像所示。 However, I was able was to set the icon image of the.exe file when I packaged it with jpackage.但是,当我用 jpackage 打包它时,我能够设置 .exe 文件的图标图像。

Basically, once I was ready to package my app I entered in Command Prompt, making sure to include the --icon option:基本上,一旦我准备好 package 我的应用程序,我就在命令提示符中输入,确保包含 --icon 选项:

jpackage --input C:\app_files\MyApp --name MyApp --main-jar myapp.jar --main-class main.MainThread --icon C:\app_files\MyApp\logo.ico --win-shortcut --dest C:\Users\Desktop\Apps --runtime-image C:\app_files\my_jre

Note: Here, at least for Windows 10, the icon image must be an.ico file.注意:这里至少为Windows 10,图标图片必须是.ico文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM