Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Java JTextPane Save

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Java JTextPane Save

    i was trying to do some simple text formatting using JEditorPane but then as knowledge grew i found JTextPane easier to implement and more robust.

    my query is how do i save the formatted text in JTextPane to file? it should be RTF or HTML or other.. as this file is not opened by the application again.

    it is a chat history text file with formatted text.

    thank you.


  2. #2

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Java JTextPane Save

    just to be clear.. it is a crime nowadays to ask for help in several forums?

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java JTextPane Save


  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Java JTextPane Save

    i ask again.. what seems to be the problem? kindly stop as other than you no one else has raised an alerm for no reason.

  6. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java JTextPane Save

    Quote Originally Posted by ikurtz View Post
    just to be clear.. it is a crime nowadays to ask for help in several forums?
    Only if you think so. One thing's sure, it won't get you more or better help.

    db

  7. #7
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java JTextPane Save

    Quote Originally Posted by ikurtz View Post
    i ask again.. what seems to be the problem? kindly stop as other than you no one else has raised an alerm for no reason.
    Since you don't seem to think there's anything wrong with cross posting, why does it bother you when your cross posting is made public knowledge?

    db

  8. #8
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Java JTextPane Save

    no not at all. it does not bother me at all to let others know im looking at other options also.

    it is your attitude that bothers me. you seem too negative.

  9. #9
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Lightbulb Re: Java JTextPane Save

    ok i solved it. sorry for the cross posting but here is the answer:

                        StyledDocument doc = (StyledDocument)textPaneHistory.getDocument();
     
                        HTMLEditorKit kit = new HTMLEditorKit();
     
                        //RTFEditorKit kit = new RTFEditorKit();
     
                        BufferedOutputStream out;
     
                        try {
                            out = new BufferedOutputStream(new FileOutputStream(chooser.getSelectedFile().getName()));
     
                            kit.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());
     
                        } catch (FileNotFoundException e) {
     
                        } catch (IOException e){
     
                        } catch (BadLocationException e){
     
                        }

  10. The Following User Says Thank You to ikurtz For This Useful Post:

    Giancarlonn (June 1st, 2012)

  11. #10
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java JTextPane Save

    Quote Originally Posted by ikurtz View Post
    no not at all. it does not bother me at all to let others know im looking at other options also.

    it is your attitude that bothers me. you seem too negative.
    Huh? Please tell me which sentence or word in my postings helped you to infer my "attitude."

    db

Similar Threads

  1. Need help with setting multiple font styles in jTextPane
    By jch02140 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2010, 06:16 AM
  2. Arraylist Save and Load
    By frankycool in forum Collections and Generics
    Replies: 1
    Last Post: November 14th, 2009, 06:48 AM
  3. Replies: 1
    Last Post: April 20th, 2009, 11:17 AM
  4. Replies: 3
    Last Post: April 20th, 2009, 08:35 AM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM