4

With Java, you can use TrayIcon and java.awt.SystemTray to make a trayicon. But this icon looks bad when you use for example Windows in combination with a 4K monitor and Windows is automatically scaling everything bigger.

Java sets the trayiconsize to 16x16 but this is way too small for the scaled mode and therefore it looks bad. Do you know how to fix this?

Edit:

Here is an example code and screenshot of the result. I am using BMW's logo (256x256 pixel) :)

package trayicon;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Trayicon {

    public static void main(String[] args) throws IOException {
        //Check the SystemTray is supported
        if (!SystemTray.isSupported()) {
            System.out.println("SystemTray is not supported");
            return;
        }
        BufferedImage img = ImageIO.read(new File("256x256.png"));
        final TrayIcon trayIcon =
                new TrayIcon(img, "Trayicon");
        trayIcon.setImageAutoSize(true);
        final SystemTray tray = SystemTray.getSystemTray();
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.out.println("TrayIcon could not be added.");
        }
        System.in.read();
        System.exit(0);
    }

}

Result (look at the lower right icon):

Trayicon

XHotSniperX
  • 712
  • 7
  • 25
  • I know this is a stupid question, but a screen shot might be nice. I've also found that if you don't supply a 16x16 image, it looks crap generally... – MadProgrammer Nov 22 '14 at 02:00
  • Ok I've updated my question with sample code and screenshot. 16x16 pixel is bad too. – XHotSniperX Nov 22 '14 at 03:01
  • @XHotSniperX Did you manage to improve the icon quality on HiDPI settings? I'm facing the same problem at the moment. :( – MrSnrub Jul 20 '23 at 02:56
  • @MrSnrub I really don't remember :D but I think I didn't manage it. Maybe a newer Java version fixed it. – XHotSniperX Aug 09 '23 at 14:59

0 Answers0