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

Serialization corrupts focus of a JButton


    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs


      Name: stC104175 Date: 05/25/2000

      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      Serialization appears to corrupt the focus behavior of a JButton.
      This is specific to JDK 1.3. The problem does not occur on JDK 1.2.2

      At the bottom is an example program which demonstrates this problem.

      Compile and run the example program under JDK 1.3.

      Press the "Press to serialize this container" button. Another Frame should come,
      titled, "Contains the serialized panel".

      The fact that the serialized "Press to serialize this container" button is
      displaying the focus selection outline is a little peculiar to me, yet I have
      not fully investigated why this is. What seems strikingly wrong is the fact that
      the serialized "Press to serialize this container" button cannot receive the
      keyboard input focus. You can test this by pressing the tab key.

      Now try running the program under JDK 1.2.2. While the serialized "Press to
      serialize this container" button still displays the selection outline, it is
      however capable of recieving the keyboard focus, as you would expect.

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

      public class Test extends JFrame
         public Test()
            final JPanel p = new JPanel()
               private void readObject(final ObjectInputStream s) throws IOException

                     //Clobbering model so button won't appear pressed
                  catch(ClassNotFoundException ex)


            p.add(new JButton("A"));

            p.add(new JButton("B"));

            JButton btn = new JButton("Press to serialize this container");

            btn.addMouseListener(new MouseAdapter()
               public void mousePressed(MouseEvent ev)
                  JFrame f = new JFrame("Contains the serialized panel");

                  catch(Exception ex)

                  f.setLocation(300, 300);


         static public Serializable recreateObjectFromObject(final Serializable
                throws IOException, ClassNotFoundException
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final ObjectOutputStream oos = new ObjectOutputStream(baos);


            final byte[] bytes = baos.toByteArray();


            final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            final ObjectInput is = new ObjectInputStream(bais);

            final Serializable retObj = (Serializable)is.readObject();


            return retObj;

         public static void main(String[] args)
            Test t = new Test();
      (Review ID: 105324)


          Issue Links



              • Assignee:
                apikalev Andrey Pikalev
                stompkinsunw Sean Tompkins (Inactive)
              • Votes:
                0 Vote for this issue
                0 Start watching this issue


                • Created: