5

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Padrus
  • 2,013
  • 1
  • 24
  • 37

1 Answers1

3

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
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1
    Maybe something like this [`AlphaTest`](http://stackoverflow.com/a/2234020/230513)? – trashgod Apr 19 '13 at 11:40
  • I could create a personal JDialog but the position should vary according to where the user has set his taskbar, it would be a lot of work just to change a small behaviour. I think I'll stick with the standard TrayIcon message. But still I'll mark your pots as the answer because I think it is the correct answer. – Padrus Apr 19 '13 at 12:56
  • 1
    @Padrus this possition is very simple to calculating, because GraphicsEnvironment returns pixels ratio and Taskbar height too, or can be calculated from JFrame.getExtendedSize, – mKorbel Apr 19 '13 at 13:06