简体   繁体   English

如何在java应用程序的文本区域显示html格式的文本?

[英]How to display html formatted text in text area of java application?

I am scraping 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.我正在使用我的 java 应用程序从网站上抓取数据,并希望在解析 Swing 中制作的文本区域中的 html 页面代码后显示结果。

Text like: hello <b>every</b>one should be displayed as: 'hello every one' in text area.文本如: hello <b>every</b>one应在文本区域显示为:'hello every one'。 Thanks!!谢谢!!

JEditorPane ep = new JEditorPane();
ep.setContentType("text/html");
ep.setText("html code");

You can use a JEditorPane to display HTML or a JTextPane, which allows you to set attributes for specific characters.您可以使用 JEditorPane 来显示 HTML 或 JTextPane,它允许您为特定字符设置属性。 Read the API and you will find a link to the Swing tutorial which provides examples.阅读 API,您将找到指向提供示例的 Swing 教程的链接。

There is no way to see formated text inside of textarea( text in name of tag mean text not html).无法看到 textarea 内的格式化文本(标签名称中的文本表示文本不是 html)。 If you don't need to submit code inside area - you can use some style magic for div element.如果您不需要在区域内提交代码 - 您可以对 div 元素使用一些样式魔术。 If you need to submit - use some WYSIWYG editor.如果您需要提交 - 使用一些 WYSIWYG 编辑器。 There is free one FCK一个免费的 FCK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM