Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a high quality OSX dock icon for an SWT Java application

Tags:

java

macos

swt

I have written an SWT Java application and would 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?

like image 230
mchr Avatar asked Feb 01 '26 12:02

mchr


2 Answers

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.

like image 171
mchr Avatar answered Feb 03 '26 00:02

mchr


You can detect OSX and use the Apple Java Extensions and call Application.setDockIconImage(...)

like image 30
Dilum Ranatunga Avatar answered Feb 03 '26 00:02

Dilum Ranatunga