简体   繁体   中英

How can I change the default icon of a java application on a mac using netbeans?

I have a java application that will need to be deployed on both windows and mac. On windows, I've configured the system to use a .png file as the icon for the application, but the mac requires an icns file. I've created the icns file, but I can't figure out how to set that as the icon to use for the application (in the dock, expose, etc). I'd also need the PC side to ignore that icon assignment.

How can I do this in netbeans?

EDIT: I added have this line in my build.xml file, as per this link :

<property name="app.icon.icns" value="${dist.dir}/Mac64/yellowMac.icns"/>

and the yellowMac.icns file is in the same directory as the .jar file, still no joy.

Call this inside the constructor

//For Microsoft Windows
setIconImage(new ImageIcon("Football.png").getImage());
//For Mac OS X
Application.getApplication().setDockIconImage(new ImageIcon("Football.png").getImage());

For Netbeans 8.0.2 you can set the .icns file for the Mac OS X bundle when Netbeans builds the native DMG package.

Make sure your .icns file has all of the required icons for a Mac OS X application bundle.

Then...

  • Right click on the project and select Properties

  • Under Build -> Deployment

  • select Enable Native Packaging

  • Click on the Icons and Splash Image: Native -> Edit... button
  • Enter a (relative) file location to your .icns file in the Native Package Icon: textfield.
  • Hit all of the required OK s.

  • Right click on you project

  • select Package as -> DMG Image

Wait a while until it says BUILD SUCCESSFUL . The .dmg file will be in the dist/bundles directory.

I was able to add a line to the file nbproject/project.properties :

app.icon.icns=yellowMac.icns

When building the Mac OSX Installer, this icns file was correctly copied over to the .app .

请注意,如果使用Java WebStart部署应用程序,则JNLP文件中的代码段允许创建包含图标的正确Mac应用程序。

in case anyone faces this problem try this

<property name="deploy.icon.native" value="p.icns"/>

where p.icns is inside the project base directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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