Java 如何更改默认 jar 图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3919647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change default jar icon
提问by Islam Hassan
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.
非常感谢。
采纳答案by Cyntech
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, e.g. 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. If you want to do the same, you'll need to create the executable 'front door', as it were, and give it an icon.
正是这个可执行文件包含应用程序图标,而不是 Java 程序。如果你想这样做,你需要创建可执行的“前门”,就像它一样,并给它一个图标。
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文件的快捷方式,更改快捷方式的图标即可。
回答by Azmisov
I use NetBeans, so if you aren't using that, I don't quite know. 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.
我使用 NetBeans,所以如果您不使用它,我不太清楚。但是,当您选择窗口时,图标文件的属性窗口中有一个选项。当您构建 .jar 时,该图标应该与程序一起构建。
回答by Tyler Treat
If you're talking about the actual application icon in, say, Windows, you can't change it (programmatically). That's determined by the OS. Although you can change it in your OS in Folder Options.
如果您谈论的是 Windows 中的实际应用程序图标,则无法(以编程方式)更改它。这是由操作系统决定的。虽然您可以在您的操作系统中的文件夹选项中更改它。
You can, however, set the window (read: JFrame) icon image using setIconImage()
.
但是,您可以使用setIconImage()
.
回答by Andrew Thompson
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,因此这应该不是问题。
回答by mohit
To set an image for MAC, you can use com.apple.eawt.Application
. try this:
要为 MAC 设置图像,您可以使用com.apple.eawt.Application
. 尝试这个:
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. If you'd like it to, (Maven) add the following dependency to your POM:
但是,默认情况下这不会在 Windows 或 Linux 上构建。如果您愿意,(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,则可以从以下位置下载 JAR http://central.maven.org/maven2/com/yuvimasory/orange-extensions/1.3.0/orange-extensions-1.3.0.jar