dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
327 stars 26 forks source link

Icon resolution limited to 16x16 on Windows #67

Closed peter277 closed 1 year ago

peter277 commented 1 year ago

Hi,

I am unable to obtain a higher resolution than 16x16 for the tray icon on Windows, which makes it appear very low res compared to other icons on Windows 10.

After a bit of searching I tried a suggestion hinted on a Stack Overflow comment here, suggesting to turn on auto size using setAutoImageSize, otherwise the Windows implementation of AWT TrayIcon targets 16x16. This suggestion actually worked so I'm sharing the concept code below. Think it would be great if functionality to enable higher res icons could be incorporated into the main library by default.

// Code for default res (results in 16x16 icon even though source image is more than 600 pixels wide and high)
// Varying this code to explicitly pass the width and height does not change the result
FXTrayIcon trayIcon = new FXTrayIcon(stage, FXTrayIcon.class.getResource("FXIconRedWhite.png"));

Resulting icon from above code on Windows 10: Default res

// High res (32x32)
FXTrayIcon2 trayIcon = new FXTrayIcon2(stage, FXTrayIcon.class.getResource("FXIconRedWhite.png"),32,32);

/** @file FXTrayIcon2.java */
import com.dustinredmond.fxtrayicon.FXTrayIcon;
import javafx.stage.Stage;
import java.net.URL;

public class FXTrayIcon2 extends FXTrayIcon {
    // Per hint on https://stackoverflow.com/questions/10820255/java-awt-systemtray-does-not-display-tray-icon-properly
    // Windows implementation of TrayIcon targets 16x16 size if you do not specify autosize on
    public FXTrayIcon2(Stage parentStage, URL iconImagePath, int width, int height) {
        super(parentStage, iconImagePath, width, height);
        super.trayIcon.setImageAutoSize(true);
    }
}

Resulting icon from above code on Windows 10 (higher resolution attained): High res

dustinkredmond commented 1 year ago

@peter277 I'm planning on pushing out a new major version release (4.0.0) later tonight. I will implement this functionality by default in that version. Thank you so much for opening this issue. I was not aware of this!