views:

59

answers:

1
public void load()
{
    final JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(this);
    if(returnVal == JFileChooser.APPROVE_OPTION)
    {
        try{
            FileInputStream f_in = new FileInputStream(fc.getSelectedFile());
            ObjectInputStream obj_in = new ObjectInputStream(f_in);
            Frame f2 = (Frame)obj_in.readObject();
            obj_in.close();
            f2.setVisible(true);
        }
        catch(Exception ex){
        }
    }
}
A: 

I'd try adding a call to the pack method on the frame before the setVisible call. This should cause it to be displayable and sized properly.

FileInputStream f_in = new FileInputStream(fc.getSelectedFile());
ObjectInputStream obj_in = new ObjectInputStream(f_in);
Frame f2 = (Frame)obj_in.readObject();
obj_in.close();
f2.pack()
f2.setVisible(true);

If this doesn't work, then check the return value of f2.isDisplayable() after the call to pack. If it is false, that means that the frame is not connected to a native screen resource (which I believe pack should take care of, but I'm uncertain of this in a deserialization scenario).

Another problem may be incompatibility between the JVM which serialized the frame and the one which is deserializing it if the frame includes Swing components. There are warnings in the javadocs for Swing components about switching JVM versions when using serialization for them.

In general, if you have a choice about serializing anything, it should only be the data model, not the view/presentation/GUI layer. So if it's an option, I'd avoid your current implementation approach entirely.

Joel Hoff