?
Solved

saving/loading JEditorPane as an object

Posted on 2002-05-21
4
Medium Priority
?
547 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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

801 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