这是我的应用程序中的代码可以正常工作:
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());
}
唯一的问题是托盘仅显示图像的左上角。 我尝试过不同的扩展和格式,但问题仍然存在。 我不好吗?有没有解决方案?
答案 0 :(得分:1)
您应该调用trayIcon方法setImageAutoSize(true),它会自动调整图像大小以完全显示为托盘图标。
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());
}
希望它有所帮助! ;)