Results 1 to 7 of 7
  1. #1
    runedog48 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default RTF (rich text format) Formatting

    Ok I have a text editor that I have made and it bolds underlines etc. but whenever I go to save it, it doesn't format it to bold etc... Do you have any tips for formatting? I opened some RTF in regular notepad and notepad ++ to see the formating but that stuff looks to complicated surely there must be another way?

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Are you using javax.swing.text.rtf.RTFEditorKit ? If so, you might consider using a different EditorKit. There is a caveat in the API for RTF that states it supports only limited functionality.

  3. #3
    runedog48 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    Are you using javax.swing.text.rtf.RTFEditorKit ? If so, you might consider using a different EditorKit. There is a caveat in the API for RTF that states it supports only limited functionality.
    The rtf what? XD I have no clue what it is and I have never heard of it before in my life except for now.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    RTFEditor kit. Im guessing you are using a JTextPane, what is the editor kit you are using on this textpane? I am working on a text editor as well, which uses a JTextPane, and a RTFEditorKit. The editor kit is helpful because it allows you to save and load. We will need more information. Mainly, what the editor kit is, and how saving and loading is accomplished.

  5. #5
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Quote Originally Posted by runedog48 View Post
    Ok I have a text editor that I have made and it bolds underlines etc. but whenever I go to save it, it doesn't format it to bold etc... Do you have any tips for formatting? I opened some RTF in regular notepad and notepad ++ to see the formating but that stuff looks to complicated surely there must be another way?
    The editor kits allow you to load, save, display, and edit text of various kinds. If you have written a home grown editor independent of the editor kit API, you could still use the editor kit to save data into RTF format. Take a look at the javax.swing.text.rtf.RTFEditorKit API. It has limited functionality, but it sounds like limited functionality is more than what you currently have, and it would save you a heck of a lot of time trying to format and parse RTF yourself.

  6. #6
    runedog48 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I am using no rtf editor... I'm using textpane. Currently there is only saving. All it does is write the text to a .rtf ..... so yeah...

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Ok. If you use a javax.swing.JEditorPane instead of a textpane, you can create one that already has RTF hooks in it.

    Java Code:
    JEditorPane editorPane = new JEditorPane("text/rtf");
    
    ...
    editorPane.getEditorKit().write(editorPane.getDocument());
    If you're using a JTextPane, you can try creating a standalone RTFEditorKit and call 'getDocument' on your JTextPane to get the Document you need to pass to the 'write' method of the RTFEditorKit.

Similar Threads

  1. Text format in JTextArea
    By goodlily in forum AWT / Swing
    Replies: 4
    Last Post: 04-10-2011, 11:57 PM
  2. Text/String format..??
    By Neullson in forum New To Java
    Replies: 14
    Last Post: 07-23-2010, 08:51 AM
  3. Text formatting and alignment according to the printer
    By java_fledgeling in forum Advanced Java
    Replies: 2
    Last Post: 06-08-2010, 10:34 AM
  4. Format some text with Java
    By vampire in forum New To Java
    Replies: 0
    Last Post: 02-18-2010, 06:45 AM
  5. Replies: 1
    Last Post: 03-16-2009, 06:05 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
  •