How do you change the Dock Icon of a Java program?

2019-01-04 13:12发布

How can I change the Dock Icon of a program, in Java, on the Macintosh platform? I have heard about using Apple's Java library (that provides some sort of extra support on the Mac platform), but I have yet to find some actual examples.

5条回答
Ridiculous、
2楼-- · 2019-01-04 13:27

While I'm not sure how to change it at runtime, you can set at the command line your Dock icon using the -Xdock:icon option, like:

 >java -Xdock:icon=/path/myIcon.png myApp

This article has lots of useful little info about bringing java apps to Mac, and you may be interested looking at the utilities and tools for Mac listed here, as well as deployment options listed here (the last link is especially useful if you want to go down the Java Webstart route).

查看更多
Fickle 薄情
3楼-- · 2019-01-04 13:41

Apple eAWT provides the Application class that allows to change the dock icon of an application.

import com.apple.eawt.Application;
...
Application application = Application.getApplication();
Image image = Toolkit.getDefaultToolkit().getImage("icon.png");
application.setDockIconImage(image);
查看更多
乱世女痞
4楼-- · 2019-01-04 13:41

If your using Eclipse, you can export a project as a Mac OS X Application Bundle and specify an .icns file to use as an icon.
In Eclipse, go to File>Export and choose the 'Mac OS X Application Bundle' option inside the 'Other' directory.

Click the next button.
Then you'll be presented with the 'Application Bundle Export Menu'.
The last option on this menu is 'Icon'. This is where you specify the .icns file to use as the dock icon.

Picture of the 2 Eclipse Export Menus

As far as creating the .icns file is concerned, you can use Apple's Icon Composer to create a .icns file from an image file. Here is a good tutorial on making mac icons.

查看更多
神经病院院长
5楼-- · 2019-01-04 13:45

For Microsoft Windows

setIconImage(new ImageIcon("Football.png").getImage());

For Mac OS X

import com.apple.eawt.Application;
Application.getApplication().setDockIconImage(new ImageIcon("Football.png").getImage());
查看更多
何必那么认真
6楼-- · 2019-01-04 13:48

If you have XCode installed, you can use JarBundler to create a Mac App using a Jar file. If you don't have XCode, you can use this JarBundler:

http://sourceforge.net/projects/jarbundler/

During the creation of the bundler, you can choose an icon in the .icns extension. That will be your Dock Icon.

查看更多
登录 后发表回答