Results 1 to 10 of 10
  1. #1
    jogendar is offline Member
    Join Date
    Jan 2010
    Posts
    13
    Rep Power
    0

    Default 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...

  2. #2
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  4. #4
    jogendar is offline Member
    Join Date
    Jan 2010
    Posts
    13
    Rep Power
    0

    Default 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..

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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."

  6. #6
    jogendar is offline Member
    Join Date
    Jan 2010
    Posts
    13
    Rep Power
    0

    Default 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??

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by jogendar View Post
    i saw in the reply above u that they doesnt save formatting,
    I didn't say that. I just stated that how you are using it will not save formatting -- big difference.

  8. #8
    jogendar is offline Member
    Join Date
    Jan 2010
    Posts
    13
    Rep Power
    0

    Default

    thanks for all u guys my problem is solved by using rtfeditor kit

  9. #9
    jogendar is offline Member
    Join Date
    Jan 2010
    Posts
    13
    Rep Power
    0

    Default

    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

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Quote Originally Posted by jogendar View Post
    the textpane is not supporting the undo/redo
    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

  1. How To add the Text field to the TextArea or TextPane
    By Chintan Patel in forum AWT / Swing
    Replies: 3
    Last Post: 04-08-2009, 03:46 AM
  2. Creating&Saving as a different Text file
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 08:17 AM
  3. Saving To A New Line Using A Text File
    By jadaleus in forum Advanced Java
    Replies: 10
    Last Post: 10-24-2008, 08:21 PM
  4. Saving To A New Line Using A Text File
    By jadaleus in forum Advanced Java
    Replies: 1
    Last Post: 10-24-2008, 01:31 AM
  5. Saving to a Text File
    By jadaleus in forum Advanced Java
    Replies: 2
    Last Post: 10-17-2008, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •