Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6552636

TrayIcon displayMessage doesn't always displays popup message

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP Professional Version 2002 Service Pack 2

      A DESCRIPTION OF THE PROBLEM :
      When GUI event dispatch thread keep making calls (every 5 seconds) to TrayIcon.displayMessage, we can see the pop up message, and can heard "pop" "pop" sound (a sound from windows xp, when there is a pop up message from system tray)

      However, if we try to close the pop up message, minimize the our Java application, and maximize any other applications (like firefox, notepad......), after some time, we can only hear the "pop" "pop" sound, but cannot see any pop up message from system tray

      If we perform double click on the our java application system tray icon, the pop up message will be shown again.



      REGRESSION. Last worked in version mustang

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. compile the given code, and have any image file as "/images/yen.png" in the resouce jar file.

      2. run the application, the pop up message can be seen and pop up message sound can be heard.

      3. minimize the java application.

      4. maximize other application like firefox, notepad.....

      5. close the pop up message

      6. "pop" "pop" sound still can be heard. but pop up message can no longer be seen.

      6. double click on the system tray icon, again, the pop up message can be seen

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "pop" "pop" sound will always be heard, and pop up message can be seen, no matter the java application is being maximized or minimized, as long as there is a call to TrayIcon.displayMessage.
      ACTUAL -
      calling TrayIcon displayMessage, will not always pop up the pop up message, if the Java application is being minimized. The behavior for this is random.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      /*
       * NewJFrame.java
       *
       * Created on April 8, 2007, 10:13 PM
       */

      package bug;

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.io.*;
      import java.util.*;

      /**
       *
       * @author doraemon
       */
      public class NewJFrame extends javax.swing.JFrame {
          
          /** Creates new form NewJFrame */
          public NewJFrame() {
              initComponents();
              
              createSystemTrayIcon();
              
              new AlertTask().execute();
          }
          
          class AlertTask extends javax.swing.SwingWorker<String, String> implements Serializable {
              
              AlertTask() {
              }

              public String doInBackground() {
                  while (! isCancelled()) {
                      publish("");
                          
                      try {
                          Thread.sleep(5000);
                      }
                      catch(java.lang.InterruptedException exp) {
                      }
                  }
                  
                  return "";
              }
              
              protected void process(java.util.List<String> strings) {
                  if(trayIcon != null) {
                      System.out.println("ask tray icon to display message");
                      trayIcon.displayMessage("Bug", "I am Java 6", TrayIcon.MessageType.INFO);
                  }
              }
          }
          
          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
          private void initComponents() {

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 400, Short.MAX_VALUE)
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 300, Short.MAX_VALUE)
              );
              pack();
          }// </editor-fold>//GEN-END:initComponents
          
          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new NewJFrame().setVisible(true);
                  }
              });
          }
          
          private void createSystemTrayIcon() {
              if (SystemTray.isSupported()) {
                  SystemTray tray = SystemTray.getSystemTray();
                  Image image = new javax.swing.ImageIcon(getClass().getResource("/images/yen.png")).getImage();

                  MouseListener mouseListener = new MouseListener() {

                      public void mouseClicked(MouseEvent e) {
                          if(e.getButton() == e.BUTTON1) {
                          }
                      }

                      public void mouseEntered(MouseEvent e) {
                      }

                      public void mouseExited(MouseEvent e) {
                      }

                      public void mousePressed(MouseEvent e) {
                      }

                      public void mouseReleased(MouseEvent e) {
                      }
                  };

                  ActionListener exitListener = new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                      }
                  };

                  PopupMenu popup = new PopupMenu();
                  MenuItem defaultItem = new MenuItem("Exit");
                  defaultItem.addActionListener(exitListener);
                  popup.add(defaultItem);

                  trayIcon = new TrayIcon(image, "JStock - KLSE Real-Time Monitor", popup);

                  ActionListener actionListener = new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                      }
                  };

                  trayIcon.setImageAutoSize(true);
                  trayIcon.addActionListener(actionListener);
                  trayIcon.addMouseListener(mouseListener);

                  try {
                      tray.add(trayIcon);
                  } catch (AWTException e) {
                      trayIcon = null;
                      JOptionPane.showMessageDialog(NewJFrame.this, "TrayIcon could not be added.", "System Tray Not Supported", JOptionPane.WARNING_MESSAGE);
                  }

              } else {
                  // System Tray is not supported

                  trayIcon = null;
                  JOptionPane.showMessageDialog(NewJFrame.this, "System tray is not supported. You may not get stock alert notify.", "System Tray Not Supported", JOptionPane.WARNING_MESSAGE);
              }
          }
          
          private transient TrayIcon trayIcon;

          // Variables declaration - do not modify//GEN-BEGIN:variables
          // End of variables declaration//GEN-END:variables
          
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            dcherepanov Dmitry Cherepanov
            Reporter:
            dav Andrei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: