How can I insert Icons inside string content in JTextPane Urgent!!!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, July 22, 2002 11:19 AM

How can I insert Icons inside string content in JTextPane. I have a string which comes from a socket and it looks like this. "Hi :) how are you doing today"; How can I display image instead of ':)' in this string on a JTextPane.
Please help me with this.

Thankyou in advance

Re: How can I insert Icons inside string content in JTextPane Urgent!!!

Posted By:   George_Tzallas  
Posted On:   Tuesday, July 23, 2002 01:59 AM

You will have to override method insertString (int, String, AttributeSet)
of javax.swing.text.StyledDocument, parse the input string, and replace any occurrences
of the pattern you want with the icon.


This is roughly an outline of the steps you will need to take. For the implementation I can only
give you two examples (there is a lot of coding involved)


  1. Check JTextField for
    an example on how to override insertString (top of the document, provides an example on how
    to convert input to uppercase, faily simple)
  2. Check /demo/jfc/StylePad for an example on how to display
    a complex document (with styles and images)

Hope this helps


Regards


George T

About | Sitemap | Contact