• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how we show HTML in the text area or Document or EditorPane

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i am working on a ui component in which i have a problem i am facing is that i have to show html code in the text area or document or editor pane
, if i use the same html code and set the label of the button then i get the right result but in the case of text i dont get the result. i am sending the code for those two cases
1> here button is a JButton and a Model is associated with it name SpclCharModel ; getHtml_code() fun give the html code crossponding to that character ;; and it works fine

Font font=new Font("Courier New",Font.PLAIN,20);
button.setFont(font);
button.setText("<HTML>" + spclCharModel.getHtml_code()+ "</HTML>");

2> here preview is an EditorPane or it may be a Document it simply print
</HTML>htmlcode<\HTML>
and e is action event which generates when the button is pushed

Font font=new Font("Courier New",Font.PLAIN,15);
previewTxt.setFont(font);
previewTxt.setText("<HTML>" + e.getSpclCharModel().getHtml_code()+ "</HTML>");
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You are almost there. You have a few constructors for a JEditorPane, and one of them works like:

Which will interpret and treat your HTML markup the way that you want. However, in your code above, the setContentType() method will probably be more useful for you since you are not supplying the text in the constructor but with the setText method.

Check out the JEditorPane javadoc for more info.

Cheers, Jared.
[ May 24, 2005: Message edited by: Jared Cope ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic