【发布时间】:2011-07-22 18:05:15
【问题描述】:
我正在编写一个在系统托盘中运行的应用程序,并在发生某些事情时通知用户(即弹出其中一个气泡)。唯一的问题是通知似乎只适用于 Windows 7,而不是 Windows XP。
我已经在 2 台 Windows 7 计算机(它们都可以工作)和 4 台 Windows XP 计算机(它们都不能工作)上对其进行了测试。没有显示通知气泡,并且(据我所知)没有抛出异常,其他一切都正常工作。我什至在 Mac 上对其进行了测试,它确实有效,但不是很漂亮。
这是我的代码示例。
private static TrayIcon trayIcon;
...
trayIcon = new TrayIcon(trayImage.getImage());
...
if (!SystemTray.isSupported())
{
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
final SystemTray tray = SystemTray.getSystemTray();
trayIcon.setToolTip("Widget Name Here [" + role + "]");
...
try
{
tray.add(trayIcon);
}
catch (AWTException e)
{
System.err.println("TrayIcon could not be added.");
return;
}
...
//Here's where it doesn't work on XP
trayIcon.displayMessage("Connection error",
"Could not connect to server, please check your internet/VPN "
+ "connection", TrayIcon.MessageType.ERROR);
任何帮助将不胜感激。
更新:好的,我刚刚确认这不是我的程序的问题,而是我一直在测试它们的 XP 安装的问题。我在 XP 计算机上运行了找到 here 的 TrayIconDemo.java 程序,但没有任何通知起作用。我开始认为我无法让它在其中一台计算机上运行......
【问题讨论】:
标签: java windows swing system-tray