Announcement

Collapse
No announcement yet.

Java 6 System Tray does not work

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Java 6 System Tray does not work

    Hi,

    I use Java 6 for my development activities. I tried the new feature included in Java 6 (Ability to access system tray). However, when I run the program, icon does not appear in the system tray. It used to work fine with Slackware 10.2 (KDE 3.4) and Windows. What is going wrong? How do I fix it?

    #2
    Re: Java 6 System Tray does not work

    Has no one else had this problem?

    Comment


      #3
      Re: Java 6 System Tray does not work

      Hi,

      I have Ubuntu 6.10 installed and have the same problem. I didn't have the chance to test my code on other OSes yet but I'm pretty sure that I did everything correctly.
      The PopupMenu of the TrayIcon works fine but the icon itself is not being displayed.

      I was also astonished to see that there doesn't seem to be a way to use a Swing PopupMenu or anything that would allow for more than just having plain text menu entries. I'm not a GUI developer so it might be that I'm missing something. However, if there is really no chance to integrate a Swing based popup with images and stuff into the tray then I'd be majorly disappointed.

      Comment


        #4
        Re: Java 6 System Tray does not work

        True it doesn't work on KDE. But Definitely JPopupMenu can be used with TrayIcon. Try this code,

        Code:
        TrayIcon trayIcon = new TrayIcon(someImage, "Tooltip", null);
        
        JPopupMenu jpopup = new JPopupMenu();
        
        JMenuItem javaCupMI = new JMenuItem("Example", new ImageIcon("javacup.gif"));
        jpopup.add(javaCupMI);
        
        jpopup.addSeparator();
        
        JMenuItem exitMI = new JMenuItem("Exit");
        jpopup.add(exitMI);
        
        trayIcon.addMouseListener(new MouseAdapter() {
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              jpopup.setLocation(e.getX(), e.getY());
              jpopup.setInvoker(jpopup);
              jpopup.setVisible(true);
            }
          }
        });

        Comment


          #5
          Re: Java 6 System Tray does not work

          Hi Chandru,

          thanks a lot for the tip!! I tried it out and it works fine.

          By the way, the tray icon now works for me.

          Originally I packed all resources into a jar file, put the tray icon under the path jdktest/tray.gif and tried to load it as follows:

          Image image = Toolkit.getDefaultToolkit().getImage("jdktest/tray.gif");
          This didn't work. Now I'm doing it like this and it works:

          URL imageURL = ClassLoader.getSystemResource("jdktest/tray.gif");
          Image image = Toolkit.getDefaultToolkit().getImage(imageURL);

          What I'm still not able to find out is how to hide the JPopupMenu once the user clicks the mouse outside of the popup region. There is not FocusEvent fired for the popupMenu in such cases and I don't want to use a MouseMotionListener for this sort of thing.
          Do you know if there is an appropriate event I could listen for in order to hide the popup whenever the user clicks outside of it?

          thanks

          Comment

          Working...
          X