Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

alok shukla
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.setText("<HTML>" + spclCharModel.getHtml_code()+ "</HTML>");

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

Font font=new Font("Courier New",Font.PLAIN,15);
previewTxt.setText("<HTML>" + e.getSpclCharModel().getHtml_code()+ "</HTML>");
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!