I have written an SWT Java application and woul开发者_如何学编程d like to configure it to use a high quality icon in the OSX dock. This is my current code:
// Prepare window
final Shell window = new Shell();
// Load icons
Display display = window.getDisplay();
ClassLoader loader = InTraceStandaloneUI.class.getClassLoader();
InputStream is16 = loader.getResourceAsStream(
"org/intrace/icons/intrace16.gif");
Image icon16 = new Image(display, is16);
is16.close();
InputStream is32 = loader.getResourceAsStream(
"org/intrace/icons/intrace32.gif");
Image icon32 = new Image(display, is32);
is32.close();
window.setImages(new Image[] {icon16, icon32});
https://github.com/mchr3k/org.intrace/blob/master/org.intrace/src/org/intrace/client/gui/InTraceStandaloneUI.java
This works for loading the 16x16 and 32x32 logos which look OK on Windows but the logo used by OSX still looks really pixelated. Do I just need to specify a third version with a higher resolution or should I be using a different image format or API?
Actually, if you call Shell.setImages(...) and include a 128x128 icon then this will be chosen by OSX and you get a high quality dock icon without having to use the Apple extension classes.
You can detect OSX and use the Apple Java Extensions and call Application.setDockIconImage(...)
Shouldn't the dock icon be referenced in the Info.plist using the
<key>CFBundleIconFile</key>
<string>icon.icns</string>
lines?
精彩评论