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

Serialization unregisters JComponent from ToolTipManager but does not reregister

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"


      A DESCRIPTION OF THE PROBLEM :
      As part of the Serialization process in Swing, a JComponent is unregistered from the ToolTipManager. But when Serialization is complete, the JComponent is not re-registered. This leads to ToolTips not being displayed after the JComponent is Serialized.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this test. Move the mouse over the buttons and the panel, notice that the tooltips display. Press the Serialization button. Notice that the tooltips no longer display. Also note the output during Serialization:
      a. Before the Serialization, the JPanel has a MouseListener that is the ToolTipManager
      b. After, there are no MouseListeners

      code:
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;

      public class TestSerializeToolTip implements Runnable, ActionListener{

          JPanel jp;
          public void run(){
      jp = new JPanel();
              jp.setToolTipText("Hi!");
              for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
              for(int i = 0; i < 10; i ++){
      JButton jb = new JButton(String.valueOf(i));
                  jb.setToolTipText(String.valueOf(i));
                  jp.add(jb);
              }
              JFrame jf = new JFrame();
              jf.add(jp);
              JButton jb = new JButton("Serialize Buttons");
              jb.addActionListener(this);
              jf.add(jb, BorderLayout.SOUTH);
              jf.pack();
              jf.setVisible(true);
          }

          public void actionPerformed(ActionEvent ae){
      try{
                  System.out.println("Before Serialization:");
                  for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  ObjectOutputStream oos = new ObjectOutputStream(baos);
                  oos.writeObject(jp);
                  System.out.println("After Serialization: " );
                  for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
              }
              catch(Exception x){ x.printStackTrace(); }
          }

          public static void main(String ... args){
              SwingUtilities.invokeLater(new TestSerializeToolTip());
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        Tooltips to still display
      ACTUAL -
      no more tooltips

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;

      public class TestSerializeToolTip implements Runnable, ActionListener{

          JPanel jp;
          public void run(){
      jp = new JPanel();
              jp.setToolTipText("Hi!");
              for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
              for(int i = 0; i < 10; i ++){
      JButton jb = new JButton(String.valueOf(i));
                  jb.setToolTipText(String.valueOf(i));
                  jp.add(jb);
              }
              JFrame jf = new JFrame();
              jf.add(jp);
              JButton jb = new JButton("Serialize Buttons");
              jb.addActionListener(this);
              jf.add(jb, BorderLayout.SOUTH);
              jf.pack();
              jf.setVisible(true);
          }

          public void actionPerformed(ActionEvent ae){
      try{
                  System.out.println("Before Serialization:");
                  for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  ObjectOutputStream oos = new ObjectOutputStream(baos);
                  oos.writeObject(jp);
                  System.out.println("After Serialization: " );
                  for(MouseListener ml: jp.getMouseListeners())
      System.out.println(ml.getClass());
              }
              catch(Exception x){ x.printStackTrace(); }
          }

          public static void main(String ... args){
              SwingUtilities.invokeLater(new TestSerializeToolTip());
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Reregister JComponents after Serialization

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: