How to display html formatted text in text area of java application?
-
19-09-2019 - |
Question
I am scrapping data from web site using my java application and want to display the result after parsing code of html page in a Text Area made in Swing.
Text like: hello <b>every</b>one
should be displayed as: 'hello everyone' in text area.
Thanks!!
Solution
You can use a JEditorPane to display HTML or a JTextPane, which allows you to set attributes for specific characters. Read the API and you will find a link to the Swing tutorial which provides examples.
OTHER TIPS
JEditorPane ep = new JEditorPane();
ep.setContentType("text/html");
ep.setText("html code");
There is no way to see formated text inside of textarea( text in name of tag mean text not html). If you don't need to submit code inside area - you can use some style magic for div element. If you need to submit - use some WYSIWYG editor. There is free one FCK