-
Bug
-
Resolution: Fixed
-
P4
-
1.4.2
-
beta
-
sparc
-
solaris_9
Name: gm110360 Date: 08/20/2004
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
SunOS csld014.unbc.ca 5.9 Generic_112233-05 sun4u sparc SUNW,Sun-Blade-100
A DESCRIPTION OF THE PROBLEM :
After a JList is serialized, the previous items in a JList are no longer visible.
The items are still in the DefaultListModel, and the Serialized copy still has the items visible.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run example, click serialize
The contents of the model after serialization will be output to System.err
the serialized copy will be loaded into a new frame titled "copy"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The original frame would still contain a JList with is elements
ACTUAL -
JList was empty
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
/** This class serves to show that the items in a JList disappear when it is
serialized. */
public class Bug2 {
public static void main(String[] args) {
final JFrame f = new JFrame();
final JPanel p = new JPanel(new BorderLayout());
final JList l = new JList(new DefaultListModel());
DefaultListModel lm = (DefaultListModel)l.getModel();
lm.addElement("test");
p.add(l, BorderLayout.CENTER);
JButton b= new JButton("serialize");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
f.setVisible(false);
try {
java.io.FileOutputStream s
= new java.io.FileOutputStream(new java.io.File("out"));
java.io.ObjectOutputStream o
= new java.io.ObjectOutputStream(s);
o.writeObject(p);
o.close();
f.setVisible(true);
// The item is still there
System.err.println(((DefaultListModel)l.getModel())
.getElementAt(0));
// Just invisible
// The saved version is OK too
FileInputStream f = new FileInputStream(new File("out"));
ObjectInputStream i = new ObjectInputStream(f);
JPanel p2 = (JPanel)i.readObject();
i.close();
JFrame frame = new JFrame();
frame.setContentPane(p2);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("copy");
frame.setVisible(true);
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
});
p.add(b, BorderLayout.NORTH);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.pack();
f.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Since the data is still in the model I made a custom wroteObject and Made a new DefaultListModel be getting the old model and copies its elements one-by-one into the new Model and then setting hteJlist to use the new model.
(Incident Review ID: 286056)
======================================================================