Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System Tray icon looks distorted

I'm trying to have an icon be added and displayed to the system tray using Java. However the icon is always either too small, or its cut off in areas. Its the second one from left in case you couldn't tell.

What am I doing wrong here? How can I get this icon to be displayed fully? What's the standard icon size to be used for system tray?

Edit: I am using AWT SystemTray and TrayIcon

like image 823
Ali Avatar asked Sep 05 '12 17:09

Ali


People also ask

How do I fix the blurry icons on my taskbar?

Display scaling settings: Go to Start > Settings > System > Display and set scaling to the Recommended setting. Uninstall third-party apps: Remove or disable third-party apps installed on your device to customize the taskbar or Start menu.

How do I reset system tray icons?

Click Start. , type Customize icons and then click Customize icons on the task bar. Click Turn system icons on or off, and then set Volume, Network, and Power System to On.


1 Answers

After you've retrieved the actual image resource from disk, you can resize it to the size you need by creating a "fake" one on-the-fly and taking its width.

I found that this was better than using the setImageAutoSize(true) method, as that method does not scale the image smoothly at all.

BufferedImage trayIconImage = ImageIO.read(getClass().getResource("/path/to/icon.png"));
int trayIconWidth = new TrayIcon(trayIconImage).getSize().width;
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
like image 99
Redandwhite Avatar answered Oct 19 '22 23:10

Redandwhite