Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default jar icon

Tags:

java

icons

jar

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.

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.

like image 937
Islam Hassan Avatar asked Oct 12 '10 22:10

Islam Hassan


5 Answers

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

like image 53
mohit Avatar answered Oct 05 '22 17:10

mohit


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.

like image 38
Cyntech Avatar answered Oct 05 '22 17:10

Cyntech


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.

like image 38
Andrew Thompson Avatar answered Oct 05 '22 17:10

Andrew Thompson


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.

like image 35
Azmisov Avatar answered Oct 05 '22 17:10

Azmisov


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().

like image 45
Tyler Treat Avatar answered Oct 05 '22 19:10

Tyler Treat