Solved

saving/loading JEditorPane as an object

Posted on 2002-05-21
4
538 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

Suggested Solutions

Title # Comments Views Activity
CSV file parsing thru Java 13 40
eclipse console opening separately 2 38
Java 8 to Java 6 8 33
junit example issue 2 27
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 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