Reputation: 1611
This is my code in my app that works fine:
if (SystemTray.isSupported()) {
popupMenu = createPopupMenu();
SystemTray systemTray = SystemTray.getSystemTray();
Image img = Toolkit.getDefaultToolkit().getImage("image.gif");
trayIcon = new TrayIcon(img);
systemTray.add(trayIcon);
trayIcon.addMouseListener(new SystemTrayMouseListener());
}
The only problem is that the Tray shows only the upper left quarter of the image. I've tried with different extension and format, but the problem still stand. Is my bad? Are there any solutions?
Upvotes: 0
Views: 183
Reputation: 920
You should call the trayIcon method setImageAutoSize(true), which will automatically resize the image to be fully displayed as a tray icon.
if (SystemTray.isSupported()) {
popupMenu = createPopupMenu();
SystemTray systemTray = SystemTray.getSystemTray();
Image img = Toolkit.getDefaultToolkit().getImage("image.gif");
trayIcon = new TrayIcon(img);
trayIcon.setImageAutoSize(true);
systemTray.add(trayIcon);
trayIcon.addMouseListener(new SystemTrayMouseListener());
}
Hope it helps! ;)
Upvotes: 1