JEditorPane. PLEASE HELP!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Atif_Farooq
Posted On:   Sunday, March 30, 2003 04:58 AM

Can anyone tell me how to view both text/html and text/plain in a JEditorPane. I have created a mail program which sends and receives mail, and when a mail is recieved it is displayed in a JEditorPane. When an email has multiparts of both text/html and text/plain, nothing is displayed. However when i recieve an email which is just one of the 2 it is displayed. I have made the JEditorPane of the form :-



JEditorPane pane = new JEditorPane("text/html", body);


where body is the plaintext or html code which needs to be displayed.

Thanks in advance!

Re: JEditorPane. PLEASE HELP!

Posted By:   Jonathan_Downey  
Posted On:   Monday, March 31, 2003 03:24 AM

Firstly, if there is both Html and Plain text in a message, the plain text is just a texted version of the Html (tags removed). Most email clients do this so that the message can be read even if someone has Html messages switched off for security reasons. (At least I think this is the case).


Anyway, in answer to your question, in the dual case why not transform the plain text into Html and display that and the Html part. All you should need to worry about is adding
to the plain text every time you encounter a line seperator. Something like:


String plain = [the plain text];
String separator = System.getProperty("line.separator");
String plainAsHtml = plain.replaceAll( separator, "
" + separator);

This code is JDK1.4 specific as replaceAll uses the Pattern/Matcher classes behind the scenes to do the replacing.

Jonathan

About | Sitemap | Contact