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 3 of 3

Thread: How can I draw a RTF formatted String to a custom JComponent?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How can I draw a RTF formatted String to a custom JComponent?

    I have my custom JComponent which do a lot of drawing operations.

    They also include drawStrings for text paragraphs, but now Id like to format the text (in a seperate window with jtextpane or another RTF editor) (bold, font-size, align, font-color, lists) and show this formatted text in my own component.

    Id like to do that without bufferedimages because if i have a big jcomponent full with images I would get a stack overflow
    Something like with AttributedString could work, but how?

    I don't really know how to get the RTF-Text out of the Jtextpane (or if there is a better editor plz tell me) and draw it in the "paintComponent(Graphics g)" method.

    The Editor is just used to format the text easily, not for the presentation (which is done with my own component)

    Can anyone help me please?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How can I draw a RTF formatted String to a custom JComponent?

    Take a look at the AttributedString class
    AttributedString (Java Platform SE 6)
    You can parse the formatting into attributes that can be added to the AttributedString, and a Graphics2D instance can draw the iterator of these String.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I draw a RTF formatted String to a custom JComponent?

    Thanks for your help,

    do you have any sample code how this works in detail? e.g. if i have a 200 words text formatted by an jtextpane. I think the difficulty is to transform the RTF of the jtextpane to an adequate Attributed String...

    Do you have any suggestions?

Similar Threads

  1. [SOLVED] Issue with mouse listeners in a custom JComponent
    By handuel in forum AWT / Java Swing
    Replies: 5
    Last Post: March 14th, 2012, 03:04 PM
  2. Draw and arc under part of a string
    By lammybun in forum Java Theory & Questions
    Replies: 3
    Last Post: February 26th, 2012, 12:26 PM
  3. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 03:29 AM
  4. Creating a formatted printable report
    By bradleysm in forum Java Theory & Questions
    Replies: 6
    Last Post: January 27th, 2011, 04:46 PM
  5. How to get unix timestamp from formatted date?
    By snytkine in forum Java Theory & Questions
    Replies: 5
    Last Post: October 12th, 2010, 08:07 AM

Tags for this Thread