简体   繁体   English

更改Java应用程序的桌面图标

[英]Changing Desktop Icon for Java Application

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. 我正在寻找一种更改Java应用程序的桌面图标的有用方法。 I've looked into this for a few days now, but am not finding an accurate result. 我已经研究了几天,但没有找到准确的结果。

Before you mark this down and call it a duplicate, I have read: How do I change the default application icon in Java? 在将其标记为重复副本之前,我已阅读: 如何更改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. 除此之外,URL示例似乎不适用于计算机上存储的文件。 I get an "uncaught error" message when I attempt to run it. 我尝试运行它时收到“未捕获的错误”消息。

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. 我正在寻找一种方法,使文件在构建后已经在计算机上保存了我应用程序的桌面图标。

For deploying Java desktop apps., the best option is usually to install the app. 对于部署Java桌面应用程序,最好的选择通常是安装该应用程序。 using Java Web Start 1 . 使用Java Web Start 1 JWS works on Windows, OS X & *nix. JWS可在Windows,OS X和* nix上运行。

  1. 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. “桌面集成”将使用启动文件中标识的图像作为桌面或菜单项图标。

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

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