简体   繁体   English

如何更改默认jar图标

[英]How to change default jar icon

First I have read all questions about this subject, so this is not a repeated question. 首先,我已阅读有关此主题的所有问题,因此这不是一个重复的问题。

What I want to ask about, how an application written in Java (such as eclipse) uses an icon instead of the default jar icons. 我想问一下,用Java编写的应用程序(如eclipse)如何使用图标而不是默认的jar图标。

I don't care about compatibility, I always can make 2 different versions of my program to Windows and Linux. 我不关心兼容性,我总是可以为Windows和Linux制作2个不同版本的程序。

How to make it in Linux and Windows. 如何在Linux和Windows中制作它。

Thanks very much. 非常感谢。

In the case of programs like eclipse, which are written in java and have a specific icon in Windows (or Linux or Mac for that matter), they actually have an OS specific executable file, eg eclipse.exe for windows, that initialises the java program. 对于像eclipse这样的程序,它们是用java编写的,并且在Windows(或Linux或Mac)中有特定的图标,它们实际上有一个特定于操作系统的可执行文件,例如用于windows的eclipse.exe,用于初始化java程序。

It is this executable that contains the application icon, not the Java program. 这个可执行文件包含应用程序图标,而不是Java程序。 If you want to do the same, you'll need to create the executable 'front door', as it were, and give it an icon. 如果你想做同样的事情,你需要创建可执行的“前门”,并给它一个图标。

If it's just for your own personal aesthetics, just create a short cut to the jar file and change the icon of the shortcut. 如果只是为了您自己的个人美学,只需创建jar文件的快捷方式并更改快捷方式的图标即可。

To set an image for MAC, you can use com.apple.eawt.Application . 要为MAC设置图像,可以使用com.apple.eawt.Application try this: 试试这个:

Image img = new ImageIcon("abc.png").getImage();  // your desired image  
Application app = Application.getApplication();
app.setDockIconImage(img);

However, this will not build on Windows or Linux by default. 但是,默认情况下,这不会构建在Windows或Linux上。 If you'd like it to, (Maven) add the following dependency to your POM: 如果您愿意,(Maven)将以下依赖项添加到您的POM:

<dependency>
    <groupId>com.yuvimasory</groupId>
    <artifactId>orange-extensions</artifactId>
    <version>1.3.0</version>
</dependency>

Or, if you don't use Maven, you can download the JAR from http://central.maven.org/maven2/com/yuvimasory/orange-extensions/1.3.0/orange-extensions-1.3.0.jar 或者,如果您不使用Maven,可以从http://central.maven.org/maven2/com/yuvimasory/orange-extensions/1.3.0/orange-extensions-1.3.0.jar下载JAR。

If the application is launched using Java Web Start , an application icon can be specified for use in desktop shortcuts and menu items. 如果使用Java Web Start启动应用程序,则可以指定应用程序图标以用于桌面快捷方式和菜单项。

Note that this icon is not attached directly to the Jar, but since the end user never sees or has to deal with a Jar, that should not be a problem. 请注意,此图标未直接附加到Jar,但由于最终用户从未看到或不得不处理Jar,因此这应该不是问题。

I use NetBeans, so if you aren't using that, I don't quite know. 我使用NetBeans,所以如果你不使用它,我不太清楚。 But, when you select the window, there is an option in the properties window for an icon file. 但是,当您选择窗口时,属性窗口中有一个图标文件选项。 When you build the .jar, that icon should be built in with the program. 在构建.jar时,该图标应该与程序一起构建。

If you're talking about the actual application icon in, say, Windows, you can't change it (programmatically). 如果您正在谈论Windows中的实际应用程序图标,则无法以编程方式更改它。 That's determined by the OS. 这是由操作系统决定的。 Although you can change it in your OS in Folder Options. 虽然您可以在文件夹选项中的操作系统中更改它。

You can, however, set the window (read: JFrame) icon image using setIconImage() . 但是,您可以使用setIconImage()设置窗口(读取:JFrame)图标图像。

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

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