Results 1 to 10 of 10
- 01-14-2010, 01:23 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
saving the text in textpane in a file with styles.
i am creating a text editor using java swings concept
this is the code i am using to save a file
jfr.setTitle(fname.getName());
FileOutputStream fop=new FileOutputStream(fname);
fop.write(jta.getText().getBytes());
fop.flush();
fop.close();
where fname is the name given in save file chooser bye the user
jta is the text pane in which the text to be saved...
my problem is that it is saving the text but not the font style,color,etc...
how to do it .. i am stuck here,please help me...
- 01-14-2010, 11:19 PM #2
Short, Self Contained, Correct Example + maybe that can help
if it fails then How to Use Editor Panes and Text Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) maybe this can help
and if all fails then look here
Answering Maschine"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
-
If what you are doing is getting the text from the component and writing it to a file, it doesn't surprise me that no formatting information is saved. I'm no pro at this, not by any means, but I believe that you want to use an editor kit, here the RTFEditorKit, to help you write to a file. I recommend you google on the terms:
java jtextpane documents saving opening RTFEditorKit
and you'll likely find useful articles such as this one:
Swing Chapter 20. (Advanced topics) Constructing a Word Processor. Easy for reading, Click here!
Hope this helps, and please let us know if you eventually work this out or not, and if so, how.
- 01-15-2010, 06:04 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
to Fubarable
thanks for ur reply,i saw the link for the artivle u hav posted but in that it is written that rtfeditorkit doesnt save the formatting in the file....
i understood that i have to use editor kit,i will try using other kits..
- 01-15-2010, 06:17 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Which article are you referring to? And where does it say that formatting is not saved?
The tutorial article says "Editor panes, by default, know how to read, write, and edit plain, HTML, and RTF text. Text panes inherit this capability but impose certain limitations. A text pane insists that its document implement the StyledDocument interface. HTMLDocument and RTFDocument are both StyledDocuments so HTML and RTF work as expected within a text pane."
The javafaq.nu article gives code and says "Save the RTF file and open it in another RTF-aware application (such as Microsoft Word) to verify compatibility."
- 01-15-2010, 06:30 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
to pbrockway2
i saw in the reply above u that they doesnt save formatting,
actually i am creating a editor which supports rtf,txt,java,c,cpp formats.
if i use rtfeditor kit for saving it,will it save the formatting for any of the formats specified above?? or shall i use any other editor kits will help me in this??
-
- 01-15-2010, 02:07 PM #8
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
thanks for all u guys my problem is solved by using rtfeditor kit
- 03-12-2010, 05:50 PM #9
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
i got a new problem with rtfeditor kit,if i use it the textpane is not supporting the undo/redo
please help me in this regard
- 03-13-2010, 09:29 PM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Have you looked at "5. Word Processor: part V - Clipboard and undo/redo"? in the Tutorial Fu linked to? It might pay to be specific If there is a problem with that implementation (eg you can't see how it transaltes into your application, or it doesn't do something you want etc).
Similar Threads
-
How To add the Text field to the TextArea or TextPane
By Chintan Patel in forum AWT / SwingReplies: 3Last Post: 04-08-2009, 02:46 AM -
Creating&Saving as a different Text file
By right2001 in forum New To JavaReplies: 2Last Post: 04-07-2009, 07:17 AM -
Saving To A New Line Using A Text File
By jadaleus in forum Advanced JavaReplies: 10Last Post: 10-24-2008, 07:21 PM -
Saving To A New Line Using A Text File
By jadaleus in forum Advanced JavaReplies: 1Last Post: 10-24-2008, 12:31 AM -
Saving to a Text File
By jadaleus in forum Advanced JavaReplies: 2Last Post: 10-17-2008, 06:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks