Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon resolution on OSX #16

Closed
craigraw opened this issue Apr 6, 2021 · 8 comments
Closed

Icon resolution on OSX #16

craigraw opened this issue Apr 6, 2021 · 8 comments

Comments

@craigraw
Copy link

craigraw commented Apr 6, 2021

I suspect that there may be no way to improve this, but the resolution of the tray icon on OSX is much poorer than other icons in the tray.

With a JavaFX Image one can use the imagename@2x.png format to supply a larger image which will be selected on a higher DPI screen. Is there any way to improve the image resolution here?

@dustinkredmond
Copy link
Owner

@craigraw Talk about perfect timing. 😄

In the last hour, I released version 2.8.0 which provides an overloaded constructor to set the icon size.

public FXTrayIcon(Stage parentStage, URL iconImagePath, int iconWidth, int iconHeight)

Please check this out, and let me know if this resolves your issue. AWT doesn't provide a lot in terms of improving resolution otherwise.

@craigraw
Copy link
Author

craigraw commented Apr 6, 2021

Good timing indeed! Unfortunately it doesn't really help though.

It does seem however that Java 9 and up supports higher DPI images through the MultiResolutionImage class which should be implemented by subclasses of java.awt.Image.

See the answer here: https://stackoverflow.com/questions/38802885/java-9-hdpi-display-support-multi-resolution-images-name-convention-and-load

Any chance of supporting this? (Possibly through an overloaded constructor where the Image is supplied)?

@EasyG0ing1
Copy link
Contributor

@craigraw I found that when I create icons following Apples guidelines then set the size to 24 x 24 in the instantiation of FXTrayIcon, it doesn't look too bad at all. It is slightly off from the other icons in the tray but you kind of have to look hard to see that.

@dustinkredmond
Copy link
Owner

@craigraw I was hoping to eliminate any AWT from the public API, I will look into this, though.

I have only done minimal testing on MacOS. I will review @EasyG0ing1's suggestion and decide how to move forward. Thank you for creating the Issue! 👍🏻

@craigraw
Copy link
Author

craigraw commented Apr 7, 2021

FWIW I've tried the MultiResolutionImage approach, and it results in better defined icons on OSX. It also works on Windows (without having to resize). Ubuntu doesn't seem to support a system tray, and prints a GTK error even if you check for support.

@dustinkredmond
Copy link
Owner

@craigraw, the Ubuntu not supporting this is a known issue, at this time, due to the complexity of adding the support, we don't feel like it's something we want to address. See #12 for further details on this.

I'm glad that the MultiResolutionImage works for OSX and Windows. If you could, would you mind creating a pull request to add this functionality to FXTrayIcon? You could create an overloaded constructor, something like below:

public FXTrayIcon(Stage parentStage, MultiResolutionImage iconImage) {
    // call this(...)
}

If you don't have time to do this, I'll leave the issue open and work on doing it myself when my small amount of free time allows. 😅

@craigraw
Copy link
Author

craigraw commented Apr 7, 2021

I found my needs were best handled by my own implementation, but essentially I'm just doing something similar to the following:

List<Image> imgList = new ArrayList<>();
imgList.add(ImageIO.read(getClass().getResource("/image.png")));
imgList.add(ImageIO.read(getClass().getResource("/image@2x.png")));
imgList.add(ImageIO.read(getClass().getResource("/image@3x.png")));
BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(imgList.toArray(new Image[0]));

this.trayIcon = new TrayIcon(mrImage, "App", popupMenu);

Here, image.png is 16x16px, image@2x.png is 32x32, and image@3x.png is 64x64.

Even though I didn't end up using FXTrayIcon, it was still valuable to reference. Thanks!

@dustinkredmond
Copy link
Owner

@craigraw, thanks for looking into it.

I will look into support for this once I migrate the project to use the latest JDK. A lot of folks using JavaFX still stick with Oracle's JDK8, simply out of convenience, so I won't look into this yet.

I'm glad, even if you're not using FXTrayIcon, that we were able to provide some good reference material for you! 🤣 In all seriousness, thanks for opening the issue, I will definitely add this to my TODO for the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants