10

On my cross-platform SWT Java application, I'm using TrayItem's setImages() function to set the dock and status bar icon. The icon is a 128x128 transparent PNG. The status and tray icons are appropriately clipped on both Windows and Linux distributions, but on the Mac I have problems that make the status bar icon appear with strange padding on both sides like this:

It's strange to me that this is working on all other platforms but the Mac. For instance, here is the same status bar icon without the problem on my Linux box:

Does anyone have any idea how to prevent this extra padding on the Mac?

9
  • Without any code this will be hard to debug. Based on some Googling, it looks like you should be able to do this without any problems.
    – jtbandes
    Jun 26, 2011 at 22:34
  • Have you tried asking the question on eclipse.platform.swt and searching bugs.eclipse.org/bugs for a possible bug? Jun 26, 2011 at 22:46
  • How does SWT Snippet 143 - dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/… - look for you? Jun 27, 2011 at 12:36
  • Did you try another image format (jpeg, gif)? I could be problem with transparency..
    – Sorceror
    Jun 27, 2011 at 13:30
  • My code is very similar to that posted in the Snippet #143. I am going to try playing with different formats, but it seems like this might be some kind of bug in SWT.
    – blimmer
    Jun 27, 2011 at 14:17

1 Answer 1

5
+100

I found the problem in SWT Cocoa sources.

public void setImage (Image image) {
    checkWidget ();
    if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
    super.setImage (image);
    double /*float*/ width = 0;
    if (image == null) {
        view.setImage (null);
    } else {
        /*
         * Feature in Cocoa.  If the NSImage object being set into the view is
         * the same NSImage object that is already there then the new image is
         * not taken.  This results in the view's image not changing even if the
         * NSImage object's content has changed since it was last set into the
         * view.  The workaround is to temporarily set the view's image to null
         * so that the new image will then be taken.
         */
        NSImage current = view.image ();
        if (current != null && current.id == image.handle.id) {
            view.setImage (null);
        }
        view.setImage (image.handle);
        if (visible) {
            width = image.handle.size ().width + BORDER;
        }
    }
    item.setLength (width);
}

The problem is on the line width = image.handle.size ().width + BORDER; which just takes pure size of image (in your case it's 128 px). I didn't found any suitable workaround (I saw you post bug report on SWT bugzilla).

So only way to avoid this bug (for now) is to make your tray image smaller.

2
  • You're right. I submitted a bug report into the SWT team a few days ago and forgot to update this post reflecting this. It's unfortunate that this problem exists because it required an intense rewrite of a large portion of code. See my bug report here
    – blimmer
    Jul 1, 2011 at 17:34
  • 2
    Just a follow-up - they have submitted a patch on the bug report if you're having the same problem.
    – blimmer
    Jul 12, 2011 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.