托盘图标显示不正确
Tray Icon displayed not properly
这是我的应用程序中运行良好的代码:
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());
}
唯一的问题是托盘仅显示图像的左上四分之一。
我试过不同的扩展名和格式,但问题仍然存在。
我的不好吗?有什么解决办法吗?
您应该调用 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());
}
希望对您有所帮助! ;)
这是我的应用程序中运行良好的代码:
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());
}
唯一的问题是托盘仅显示图像的左上四分之一。 我试过不同的扩展名和格式,但问题仍然存在。 我的不好吗?有什么解决办法吗?
您应该调用 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());
}
希望对您有所帮助! ;)