Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

saving/loading JEditorPane as an object

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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.
Suggested Courses

604 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