Name: gm110360 Date: 02/13/2004
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
JLayeredPane does not seem to support serialization via the java.beans XMLEncoder / XMLDecoder methods. The components that are added to the layered pane lose their layer attributes during serialization (they simply don't appear in the XML file), and they therefore do not appear during de-serialisation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a JLayeredPane, with several overlapping components.
2. Serialize.
3. Deserialize.
4. Observe that no components are displayed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That the components will be displayed on the de-serialized JLayeredPane in the correct layering order as they were at at the time of serialization.
ACTUAL -
No components are displayed at all. Additionally, no layer information appears to exist in the XML serialization file.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.*;
public class test
{
public static String fileName = "LPTest.xml";
public static void main(String[] args)
{
if (args.length != 1)
{
System.out.println("java test [serialize|deserialize]");
System.exit(1);
}
JFrame f = new JFrame("test");
JLayeredPane lp = null;
if (args[0].toLowerCase().equals("serialize"))
lp = test.serialize();
else if (args[0].toLowerCase().equals("deserialize"))
lp = test.deserialize();
else
{
System.out.println("Invalid argument!");
System.exit(1);
}
lp.setSize(200,200);
f.setSize(200,200);
f.getContentPane().add(lp);
f.setVisible(true);
}
public static JLayeredPane serialize()
{
JLayeredPane lp = new JLayeredPane();
lp.setSize(200,200);
JPanel pan1 = new JPanel();
pan1.setBackground(Color.blue);
pan1.setLocation(0,0);
pan1.setSize(50,50);
JPanel pan2 = new JPanel();
pan2.setBackground(Color.red);
pan2.setLocation(25,25);
pan2.setSize(50,50);
JPanel pan3 = new JPanel();
pan3.setBackground(Color.yellow);
pan3.setLocation(40,40);
pan3.setSize(50,50);
lp.add(pan2, new Integer(0));
lp.add(pan1, new Integer(1));
lp.add(pan3, new Integer(2));
try
{
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(fileName)));
e.writeObject(lp);
e.flush();
e.close();
}
catch (FileNotFoundException e1)
{
System.out.println("Failed to write to " + fileName);
System.exit(1);
}
return lp;
}
public static JLayeredPane deserialize()
{
JLayeredPane lp = null;
try
{
XMLDecoder d = new XMLDecoder(
new BufferedInputStream(
new FileInputStream(fileName)));
lp = (JLayeredPane) d.readObject();
d.close();
}
catch (FileNotFoundException e)
{
System.out.println("Serialisation file " + fileName + " did not exist!");
System.exit(1);
}
if (lp == null)
{
System.out.println("Serialisation file " + fileName + " did not contain a valid component!");
System.exit(1);
}
return lp;
}
}
---------- END SOURCE ----------
(Incident Review ID: 187506)
======================================================================