Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving with JTextPane & Attributes handling

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, thanks for the saving.
Do you have any response for the attributes handling problem?
Thanks,
John Price aka cc11rocks
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This isn't working for some reason.
cc11rocks aka John Price
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic