可能重复:
How can I run a Windows GUI application on as a service?
我已经为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服务模式下触发,请告诉我。