更改 Java 应用程序的桌面图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18173638/
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
Changing Desktop Icon for Java Application
提问by Jeremy Johnson
I wish to thank you in advance for taking the time to read my question, and I would greatly appreciate any comments, answers, insights, techniques and critiques that you may be able to provide.
我要提前感谢您抽出时间阅读我的问题,如果您能提供任何评论、答案、见解、技术和批评,我将不胜感激。
I'm looking for a useful method for changing the desktop icon for a Java application. I've looked into this for a few days now, but am not finding an accurate result.
我正在寻找一种有用的方法来更改 Java 应用程序的桌面图标。我已经研究了几天,但没有找到准确的结果。
Before you mark this down and call it a duplicate, I have read: How do I change the default application icon in Java?to others who asked this question), but this does not address my specific problem. I know that their method utilizes a url location instead of an import, but I am trying to learn how to use this with the import(if that is, in fact, possible). When I attempt to use their method for changing by source location. Besides that, the url example doesn't seem to work for a file stored on the computer. I get an "uncaught error" message when I attempt to run it.
在您将其标记为重复之前,我已阅读:如何更改 Java 中的默认应用程序图标?对问这个问题的其他人),但这并没有解决我的具体问题。我知道他们的方法使用 url 位置而不是导入,但我正在尝试学习如何在导入中使用它(如果这实际上是可能的)。当我尝试使用他们的方法按源位置进行更改时。除此之外,url 示例似乎不适用于存储在计算机上的文件。当我尝试运行它时,我收到一条“未捕获的错误”消息。
I use the following format to declare an image that I have imported into NetBeans:
我使用以下格式声明已导入 NetBeans 的图像:
Image image = new ImageIcon("imported.png").getImage();
frame.setIconImage(image);
Now this works fine for the icon that displays in the toolbar and it also appears in the upper left-hand corner of the frame, but I still have the Java coffee-cup as the icon for the application when I clean and build it.
现在,这对于工具栏中显示的图标很有效,它也出现在框架的左上角,但是当我清理和构建应用程序时,我仍然使用 Java 咖啡杯作为应用程序的图标。
For additional resources to the code that I am using to attempt this:
对于我用来尝试此操作的代码的其他资源:
import java.awt.Image;
import javax.swing.*;
public class Check {
JFrame frame;
public static void main(String[] args) {
new Check().go();
}
private void go() {
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image image = new ImageIcon("owl.gif").getImage();
frame.setIconImage(image);
frame.setVisible(true);
frame.setSize(300, 300);
}
}
The "owl.gif" bit is what I imported into NetBeans by click and drag method (as described in one of the books that I read that focused on NetBeans).
“owl.gif”位是我通过单击和拖动方法导入到 NetBeans 中的内容(如我阅读的一本专注于 NetBeans 的书中所述)。
I'm looking for a way to make a file that I already have saved on my computer the desktop icon for my application after it is built.
我正在寻找一种方法,使我已经保存在计算机上的文件在构建后成为我的应用程序的桌面图标。
采纳答案by Andrew Thompson
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start1. JWS works on Windows, OS X & *nix.
对于部署 Java 桌面应用程序,最好的选择通常是安装应用程序。使用Java Web Start 1。JWS 适用于 Windows、OS X 和 *nix。
- JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
- JWS 提供了许多吸引人的功能,包括但不限于启动画面、桌面集成、文件关联、自动更新(包括延迟下载和更新的编程控制)、按平台、架构或 Java 版本、配置对本机和其他资源下载进行分区运行时环境(最低 J2SE 版本、运行时选项、RAM 等),使用扩展轻松管理公共资源。
The 'desktop integration' will use the image identified in the launch file as the desktop or menu item icon.
“桌面集成”将使用启动文件中标识的图像作为桌面或菜单项图标。