-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2
-
beta
-
x86
-
windows_nt
Name: rlT66838 Date: 08/23/99
JCheckBox gets corrupted after being serialized
I'm following up Bug #ID 4107584, which wasn't fully
addressed. This bug appears similar to, but is not the
same as Bug #ID 4264798, which I have recently submitted.
The bug report that I am presently submitting applies
specifically to the effects of serialization on a JCheckBox.
At least two side-effects occur when a JCheckBox is serialized:
1.) The JCheckBox's border is set to null.
2.) The JCheckBox no longer is able to receive input
Below is an example which demonstrates this behavior. You will
notice from the standard output that the border of the JCheckBox
on the left is set to null after being serialized. If you attempt
to click the JCheckBox on the left, it will have no effect.
//Source code is below
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class A extends JFrame
{
public A()
{
super();
final JPanel p = new JPanel(new FlowLayout());
final JCheckBox cb = new JCheckBox();
p.add(cb);
p.add(copyComponent(cb));
setContentPane(p);
}
//Makes a copy of the source component using serialization
//As a side-effect, due to a bug, the source component border gets its border clobbered
private JComponent copyComponent(final JComponent source)
{
JComponent copy = null;
try
{
System.out.println("source's border prior to copying = " + source.getBorder());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutput os = new ObjectOutputStream(baos);
os.writeObject(source);
os.flush();
os.close();
baos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInput is = new ObjectInputStream(bais);
copy = (JComponent)is.readObject();
System.out.println("source's border after copying = " + source.getBorder());
System.out.println();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return copy;
}
public static void main(String args[] )
{
A a = new A();
a.pack();
a.setVisible(true);
}
}
(Review ID: 94260)
======================================================================