开发者

How to change default jar icon

First I have read all question开发者_运维百科s 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.

I don't care about compatibility, I always can make 2 different versions of my program to Windows and Linux.

How to make it in Linux and 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, e.g. eclipse.exe for windows, that initialises the java program.

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.

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.


To set an image for MAC, you can use 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. If you'd like it to, (Maven) add the following dependency to your 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


If the application is launched using Java Web Start, an application icon can be specified for use in desktop shortcuts and menu items.

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.


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.


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.

You can, however, set the window (read: JFrame) icon image using setIconImage().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜