Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Java's TrayIcon message to fade out?

I have a Java application that reduce into the system tray when the red cross is pressed.

Whenever this happen, I display a message to inform the user that the application is still running in the system tray.

Here's the code for that :

...

    @Override
    public void windowClosing(WindowEvent e) {
       try {
            tray.add(trayIcon);
            trayIcon.displayMessage("", "The application has been reduced
                 in the system tray, to stop it, press the \"Quit\" button", 
                 TrayIcon.MessageType.WARNING);
            setVisible(false);
        } catch (AWTException ex) {
            System.out.println("unable to add to tray");
        }
    }
...

For the moment, the message disappears if the user clicks on it.

I would like to set up a counter so the message would fade out after a couple of seconds even if nothing has been done.

Does anyone know a nice way to do it cause I can't seem to find any existing method for that.

EDIT

I have to correct my question, in fact, after testing it a little bit longer, it automatically fades out after, let's say, 7-8 seconds but I find it a little bit too long. Also, it only disappears if the user is executing an action (moving the mouse or typing on the keyboard)

So the new question would be : Is there a way to reduce the fade out time and change the message behaviour by configuring the Java application or is it inherent to Windows?

like image 843
Padrus Avatar asked Oct 21 '22 12:10

Padrus


1 Answers

So the new question would be : Is there a way to reduce the fade out time by configuring the Java application or is it inherent to Windows?

  • MSDN says in part How long to notify - In Windows Vista and later, notifications are displayed for a fixed duration of 9 seconds.

  • any changes is possible to maintain only on Windows size, but seems like is valid/applied for all messagess


  • you can to create own Traslucent JDialog (Transparency could be way too) placed programatically to the left bottom, fading out will be invoked from Swing Timer
like image 194
mKorbel Avatar answered Nov 01 '22 09:11

mKorbel