简体   繁体   中英

Java TrayIcon.displayMessage() does not work on Windows XP

I'm writing an application that runs in the System Tray and notifies the user (ie makes one of those bubbles pop up) when something happens. The only problem is that the notifications only seem to work on Windows 7, and not Windows XP.

I've tested it on 2 Windows 7 computers (they've both worked) and 4 Windows XP computers (none of them have worked). No notification bubble is shown, and (as far as I know) no exceptions are thrown and everything else works as it should. I've even tested it on a Mac, and it worked, but it wasn't too pretty.

Here is a sample of my code.

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);

Any help would be much appreciated.

UPDATE: Ok, I've just confirmed that it's not a problem with my program, but a problem with the XP installations I've been testing them on. I ran the TrayIconDemo.java program found here on an XP computer and none of the notifications worked. I'm starting to think there's nothing I can do to get it to work on one of these computers...

Okay, so I've finally found the solution to my problem. It turned out that the following key was set to 0 (false) by default on the installations I was testing on:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\EnableBalloonTips

To enable the notification bubbles, simply set the value to 1 .

I have Windows XP and working on system tray application. I have just added displayMessage() and it works just fine for me. Try to simplify your application. I am sure it will work. The find a bug.

EDIT: you didn't mentioned JRE version System try required Java6

this should be comment, but this is restrict for chars lenght

maybe, there is another reason in case of when Java updates are distributed by some of administrations tool for AD or ZenWorks, then sometimes (on both win7/Xp) is needed un-install all java instalactions and install fresh JRE manually (but stable 1.6.022 my view), sw distibutions ends without error, but all (???) classes/methods/changes cames from Java6 weren't accesible, on partial (RowSorter etc...) test ends with error, and I never search for knows Bugs on MS, Novell...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM