I've written a Java app that can be used on both Windows and Linux. The app uses a TrayIcon. On Windows, this works perfectly, but on Linux (CentOS) the TrayIcon has 2 problems: 1) I've lost the transparency in my png image) and 2) the image looks like it is shifted up (more on this later).
I take into account the the different environments by getting the tray icon size and then scaling accordingly. Here is my code:
Dimension trayIconSize = tray.getTrayIconSize();
Image originalImage = toolkit.getImage("tray_icon.png");
Image scaledImage = originalImage.getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH);
trayIcon = new TrayIcon(scaledImage, "Some Text");
On CentOS, the returned dimension for .getTrayIconSize() is 24x24, but after testing, it's actually fits a 24x32 (WxH) image, which accounts for the image appearing shifted up when it is set to 24x24.
Is there any way to maintain the background transparency? Also, any suggestions on getting a properly sized icon dynamically?