This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Saving with JTextPane & Attributes handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Saving with JTextPane & Attributes handling" Watch "Saving with JTextPane & Attributes handling" New topic
Author

Saving with JTextPane & Attributes handling

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495


This all compiles and runs fine.

Problems: Saving and Attributes handling

Problem in Detail: Saving: JTextPane saves data to a test file ("testfile.txt"). Doesn't information such as italics, bold, and size.

Problem in Detail: Attributes handling:
When you click to another area in the JTextPane (called "area"), the buttons are off. When you click one of the Attributes buttons while not at the end, it takes the attributes from the end and places them in the spot where you are typing.

What am I doing wrong and how do I fix them?

Thanks,
John Price aka cc11rocks

EDIT: Should I use a caret listener to fix the attributes problem?


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The API documentation for the "write" method of JTextPane says:

Stores the contents of the model into the given stream. By default this will store the model as plain text.


So you can't use that. You're going to have to serialize the Document which underlies the text component yourself. I don't know if there's a standard way to do that, but when I had to do it I serialized it as XML (I made up my own XML format for that).
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Okay, thanks for the saving.
Do you have any response for the attributes handling problem?
Thanks,
John Price aka cc11rocks
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495


This isn't working for some reason.
cc11rocks aka John Price
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving with JTextPane & Attributes handling