0

I would like to learn how to save a JInternalFrame.
Currently reading through Serialize info.
I have never ran the app outside of Netbeans. I have had no success with creating
the jar for the app (JDesktopPane). Now Serialization is adding to the confusion.

Do I have to have the JMenuItem on the JInternalFrame to open a JFileChooser to save the
file in a Location and call a method or class to use the Streams to put it there?
Thanks

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

In a word - yes.
You need to call JFileChoser in response to some kind of user interaction - eg clicking a menu item.
The JFileChooser returns you a File object, so you then open some kind of output Stream (eg new ObjectOutputStream) to that File, and write your data to the Stream

0

In a word - yes.
You need to call JFileChoser in response to some kind of user interaction - eg clicking a menu item.
The JFileChooser returns you a File object, so you then open some kind of output Stream (eg new ObjectOutputStream) to that File, and write your data to the Stream

Thanks. I am on the right trail then. However,I have been able to collect info on
JFileChooser and Serializable but not a single example that shows them working together.
They both seem like vital operations. I wonder why there is a void in code examples.

0

JFileChooser gives you a file.
Serialization writes to a file.
You really don't need anything else. Just start with the file chooser and use its file in the serialization. One just goes right after the other. Try it.

0

Here, stripped of all the error handling etc, is the essential sequence of steps:

JFileChoser jfc = new JFileChoser(...
jfc.showSaveDialog(...
File f = jfc.getSelectedFile();
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(myObject);
oos.close();

You can get all the error and exception handling from the examples you have already found.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.