Solved

saving/loading JEditorPane as an object

Posted on 2002-05-21
4
539 Views
Last Modified: 2008-03-04
Hi there,
I have an application that has an JEditorPane area where I write text and draw basic shapes(circle, square). When saving the JEditorPane as an object to a file (after I typed some text)I have this error :
java.io.NotSerializableException: javax.swing.text.JTextComponent$InputMethodReq
uestsHandler

anyway if I paste some text and not typping it I can save the object along with the graphic (e.g. circle)

The problem is when I am loading back the object I can see just the text I saved and not the circle as well...

Why is that?
0
Comment
Question by:pelau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 7025335
How are you writing out the document? Can you post the relevant code?
0
 

Author Comment

by:pelau
ID: 7025386

[...]
//saving the jeditorpane area
//I have omited try-catch for easy understanding
MyJEditor jeditorPane = new MyJEditor();
//this myjeditor is a derived class from JEditorPane.
File fileName = fileChooser.getSelectedFile();
ObjectOutputStream objOut = new ObjectOutputStream(new FileOutputStream(fileName));
objOut.writeObject(jeditorPane);
objOut.flush();


//and loading back the object:

MyJEditor mj = (MyJEditor)objIn.readObject();
c.add(mj, BorderLayout.CENTER);
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 100 total points
ID: 7025491
Well, I'm not sure what content type you've specified. But I don't think it really matters. Let me suggest that the way to write and read the content is to use the EditorKit associated with the JEditorPane. An EditorKit is responsible for supporting an appropriate Document model for a specific content type. An EditorKit is meant to specifically support one type of content, a String description of which should be retrievable with the getContentType() method. A corresponding Document instance should be returned by the createDefaultDocument() method, and the EditorKit should be able to read() and write() that Document to InputStreams/OutputStreams and Readers/Writers, respectively.

Example:

    File file = fileChooser.getSelectedFile();
    OutputStream out = new FileOutputStream(file);
    EditorKit kit = pane.getEditorKit();
    Document doc = pane.getDocument();
    kit.write(out, doc, 0, doc.length());
    out.flush();
    out.close();

This may still not solve your problem relative to images because the EditorKit for the content type may not support reading/writing images. RTF, I think, does not. But this is starting to stray into an area where I'm not sure I can help much.

Here are a few links to additional information resources that might prove helpful:
http://www.jalice.net/attributes.htm
http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/index.html

I'll post others as I find them.
Jim
0
 

Author Comment

by:pelau
ID: 7035319
thanks, I will try the editorkit thing .
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question