我为 Windows 7 添加了启用 SystemTrayIcon 的代码。它在 NetBeans 应用程序模式下运行良好,而我在 Windows 服务模式下执行应用程序时它不起作用。请找到以下代码供您参考。
if (!java.awt.SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
Image img1 = new ImageIcon(DataReporter.class.getResource("/lookandfeel/data/xear_appIcon_16.png")).getImage();
ImageIcon icon = new ImageIcon(img1);
final TrayIcon trayIcon = new TrayIcon(icon.getImage());
trayIcon.setToolTip(DataReporterProps.softwareDescriptionText);
final java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray();
MenuItem aboutItem = new MenuItem("About");
popup.add(aboutItem);
trayIcon.setPopupMenu(popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("Cannot add the TrayIcon!");
}
请让我知道是否要添加任何代码以在 Windows 服务模式下触发。